ExtJs 6.02使用配置存储remoteSort和groupField使存储自动加载

时间:2016-06-13 15:42:48

标签: javascript extjs extjs6 extjs6-classic

所以问题是如果用

实例化商店
  

remoteSort

  

groupField

商店以自动加载的方式触发对服务器的请求。

例如

Ext.create('Ext.data.Store',{
  remoteSort: true,
  groupField: 'someProperty',
  model: 'MyApp.model.SomeModel',
  proxy: {
    type: 'ajax',
    api: {
      read: 'myRestUrl'
    },
    reader: {
      type: 'json',
      rootProperty: 'data'
    }
  }
});

以上内容触发

请求
  

myRestUrl

它不应该。

使用ExtJs 6.02

1 个答案:

答案 0 :(得分:0)

所以要避免拥有

商店
  

remoteSort:true

  

groupField

要自动加载,我在group

上覆盖了'Ext.data.AbstractStore'方法
/**
 * Groups data inside the store.
 * @param {String/Object} grouper Either a string name of one of the fields in this Store's
 * configured {@link Ext.data.Model Model}, or an object, or a {@link Ext.util.Grouper grouper} configuration object.
 * @param {String} [direction] The overall direction to group the data by. Defaults to the value of {@link #groupDir}.
 */
group: function(grouper, direction) {
    var me = this,
        sorters = me.getSorters(false),
        change = grouper || (sorters && sorters.length)

    if (grouper && typeof grouper === 'string') {
        grouper = {
            property: grouper,
            direction: direction || me.getGroupDir()
        };
    }

    me.settingGroups = true;
    me.getData().setGrouper(grouper);
    delete me.settingGroups;

    if (change) {
        if (me.getRemoteSort()) {
            /**
             * when grouping a store only if the store is loaded trigger a load otherwise
             * the store would be autoloading.
             */
            if(me.isLoaded()) {
                me.load({
                  scope: me,
                  callback: me.fireGroupChange
                });
            }
        } else {
            me.fireEvent('datachanged', me);
            me.fireEvent('refresh', me);
            me.fireGroupChange();
        }
    }
    // groupchange event must fire when group is cleared. 
    // The Grouping feature forces a view refresh when changed to a null grouper 
    else {
        me.fireGroupChange();
    }
},

});