GridUtil.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. Ext.define('saas.util.GridUtil', {
  2. BaseUtil: Ext.create('saas.util.BaseUtil'),
  3. /**
  4. * 获取grid列配置
  5. * @param grid grid组件
  6. * @param url 请求url
  7. */
  8. setColumns: function(grid, url) {
  9. this.BaseUtil.request({url})
  10. .then(function(response) {
  11. var columns = Ext.decode(response.responseText);
  12. var fields = columns.map(column => column.dataIndex);
  13. var store = Ext.create('Ext.data.Store', {
  14. fields,
  15. });
  16. if(grid.showIndex) {
  17. columns.unshift({ xtype: 'rownumberer' });
  18. }
  19. grid.reconfigure(store, columns);
  20. grid.fireEvent('afterSetColumns', grid, columns);
  21. })
  22. .catch(function(response) {
  23. // something...
  24. });
  25. },
  26. /**
  27. * 获取grid数据
  28. * @param grid grid组件
  29. * @param url 请求url
  30. */
  31. loadData: function(grid, url) {
  32. this.BaseUtil.request({url})
  33. .then(function(response) {
  34. var data = Ext.decode(response.responseText);
  35. grid.getStore().loadData(data);
  36. grid.fireEvent('afterLoadData', grid, data);
  37. })
  38. .catch(function(response) {
  39. // something...
  40. });
  41. }
  42. });