ExtJs 中 gridpanel 分组后组名排序

ExtJs 中对 gridpanel 分组后的组名进行排序,GroupingGrid 分组后是不能对组名再进行排序的,本文介绍了相关方法。

group

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
  * 定义降序的groupingStore
  */
var DescGroupingStore = Ext.extend(Ext.data.GroupingStore, {
groupDir : 'ASC',
groupBy : function(field, forceRegroup, direction) {
    direction = direction ? (String(direction)
              .toUpperCase() == 'DESC' ? 'DESC' : 'ASC')
              : this.groupDir;
    if (this.groupField == field
           this.groupDir == direction && !forceRegroup) {
          return;
   }
   this.groupField = field;
   this.groupDir = direction;
   if (this.remoteGroup) {
       if (!this.baseParams) {
          this.baseParams = {};
       }
       this.baseParams['groupBy'] = field;
          this.baseParams['groupDir'] = direction;
       }
       if (this.groupOnSort) {
            this.sort(field, direction);
            return;
       }
       if (this.remoteGroup) {
            this.reload();
       } else {
            var si = this.sortInfo || {};
            if (si.field != field || si.direction != direction) {
                this.applySort();
            } else {
                this.sortData(field, direction);
            }
            this.fireEvent('datachanged', this);
        }
    },
    applySort : function() {
        Ext.data.GroupingStore.superclass.applySort.call(this);
        if (!this.groupOnSort && !this.remoteGroup) {
            if (this.groupField != this.sortInfo.field
                    || this.groupDir != this.sortInfo.direction) {
                this.sortData(this.groupField, this.groupDir);
            }
        }
    },
    applyGrouping : function(alwaysFireChange) {
        if (this.groupField !== false) {
            this.groupBy(this.groupField, true, this.groupDir);
            return true;
        } else {
            if (alwaysFireChange === true) {
                this.fireEvent('datachanged', this);
            }
            return false;
        }
    }
});
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
/*************************调用***************************/
// 消息列表数据源
var messageStore = new DescGroupingStore({
  proxy: new Ext.data.HttpProxy({
    url: "listMessGrid.action"
  }),
  reader: myReader,
  groupDir: "DESC",
  groupField: "status",
  sortInfo: {
    field: "id",
    direction: "DESC"
  }
});
messageStore.load();
1
2
3
4
5
6
/*****************在gridpanel中添加如下属性*************************************/
view: new Ext.grid.GroupingView({
  showGroupName: false,
  groupTextTpl: "{gvalue}:{text}",
  showGroupsText: "ddd"
});
Built with Hugo
Theme Stack designed by Jimmy