简体   繁体   English

具有配置remoteSort和groupField的ExtJs 6.02存储使存储自动加载

[英]ExtJs 6.02 Store with configs remoteSort and groupField makes the store to auto load

So the issue is that if you instantiate a store with 所以问题是,如果您使用

remoteSort 远程排序

and

groupField groupField

the store triggers a request to the server behaving in an auto-load way. 商店会以自动加载的方式触发对服务器的请求。

eg 例如

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

The above triggers a request to 上面触发了一个请求

myRestUrl myRestUrl

and it should not. 它不应该。

Using ExtJs 6.02 使用ExtJs 6.02

So to avoid having a store with 因此,避免与

remoteSort: true remoteSort:正确

and

groupField groupField

to be auto loaded, I overrode group method on 'Ext.data.AbstractStore' 要自动加载,我覆盖了'Ext.data.AbstractStore''Ext.data.AbstractStore' group方法

/**
 * 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();
    }
},

}); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM