簡體   English   中英

具有配置remoteSort和groupField的ExtJs 6.02存儲使存儲自動加載

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

所以問題是,如果您使用

遠程排序

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

因此,避免與

remoteSort:正確

groupField

要自動加載,我覆蓋了'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