Ext.lingo.PlainGrid.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Ext JS Library 2.0.2
  3. * Copyright(c) 2006-2008, Ext JS, LLC.
  4. * licensing@extjs.com
  5. *
  6. * http://www.extjs.com/license
  7. *
  8. * @author Lingo
  9. * @since 2008-03-23
  10. * http://code.google.com/p/anewssystem/
  11. */
  12. Ext.namespace("Ext.lingo");
  13. /**
  14. * 拥有CRUD功能的表格.
  15. *
  16. * @param config 需要的配置{}
  17. */
  18. Ext.lingo.PlainGrid = Ext.extend(Ext.grid.GridPanel, {
  19. loadMask: true,
  20. urlPagedQuery: "pagedQuery.do",
  21. pageSize: 15,
  22. // 初始化
  23. initComponent: function() {
  24. this.buildColumnModel();
  25. this.buildRecord();
  26. this.buildDataStore();
  27. this.buildToolbar();
  28. Ext.lingo.PlainGrid.superclass.initComponent.call(this);
  29. },
  30. // 初始化ColumnModel
  31. buildColumnModel: function() {
  32. this.sm = new Ext.grid.CheckboxSelectionModel();
  33. var columnHeaders = new Array();
  34. columnHeaders[0] = new Ext.grid.RowNumberer();
  35. columnHeaders[1] = this.sm;
  36. for (var i = 0; i < this.formConfig.length; i++) {
  37. var col = this.formConfig[i];
  38. if (col.hideGrid === true) {
  39. continue;
  40. }
  41. columnHeaders.push({
  42. header: col.fieldLabel,
  43. sortable: col.sortable,
  44. dataIndex: col.name,
  45. renderer: col.renderer
  46. });
  47. }
  48. this.cm = new Ext.grid.ColumnModel(columnHeaders);
  49. this.cm.defaultSortable = true;
  50. this.columnModel = this.cm;
  51. },
  52. buildRecord: function() {
  53. this.dataRecord = Ext.data.Record.create(this.formConfig);
  54. },
  55. buildDataStore: function() {
  56. this.store = new Ext.data.Store({
  57. proxy : new Ext.data.HttpProxy({url:this.urlPagedQuery}),
  58. reader : new Ext.data.JsonReader({
  59. root : "result",
  60. totalProperty : "totalCount",
  61. id : "id"
  62. }, this.dataRecord),
  63. remoteSort : true
  64. });
  65. // this.store.setDefaultSort("id", "DESC");
  66. },
  67. buildToolbar: function() {
  68. // 把分页工具条,放在页脚
  69. var paging = new Ext.PagingToolbar({
  70. pageSize: this.pageSize,
  71. store: this.store,
  72. displayInfo: true,
  73. displayMsg: '显示第 {0} 条到 {1} 条记录,一共 {2} 条',
  74. emptyMsg: "没有记录",
  75. plugins : [new Ext.ux.PageSizePlugin()]
  76. });
  77. this.store.load({
  78. params:{start:0, limit:paging.pageSize}
  79. });
  80. this.bbar = paging;
  81. }
  82. });