Ext.data.Store getTotalCount() doesn't calculate after load

試著忘記壹切 提交于 2019-12-06 06:49:03

问题


My store doesn't always return the right amount of records when calling getTotalCount(). This problem occurs after I load() the store. I know that there are records in the store at that point of checking.
I am using ExtJs 4.1.3

//this.grid = reference to my grid
var count = this.grid.getStore().getCount(), //50
    total = this.grid.getStore().getTotalCount(); //16000

    this.grid.getStore().load();

    count = this.grid.getStore().getCount(); //50
    total = this.grid.getStore().getTotalCount(); //0

How can I get the number of records that could be loaded into the Store if the Store contained all data?


My store configuration.

store: Ext.create('Ext.data.Store', {
                model: me.modelName,
                remoteSort: true,
                remoteFilter: true,
                pageSize: 50,
                trailingBufferZone: 25,
                leadingBufferZone: 50,
                buffered: true,
                proxy: {
                    type: 'ajax',
                    actionMethods: { read: 'POST' },
                    api: {
                        read: me.urls.gridUrl
                    },
                    extraParams: Ext.applyIf({ FilterType: 0 }, me.urlParams.gridUrlParams),
                    simpleSortMode: true,
                    reader: {
                        type: 'json',
                        root: 'data',
                        totalProperty: 'total'
                    }
                },
                autoLoad: true
            })

I can confirm that the total property is send for all of my requests.

{
    "succes": true,
    "data": [
    //50 records
    ],
    "total": 16219,
    "errors": []
}

回答1:


Load is asynchronous. When you call it, the store deletes the total count property, and by the time you reach the two lines after load most chances the server hasn't returned yet to update the property:

this.grid.getStore().load();

// Server hasn't returned yet for these two lines.
count = this.grid.getStore().getCount();
total = this.grid.getStore().getTotalCount();

You should really write:

this.grid.getStore().load({
    scope: this,
    callback: function(records, operation, success) {
        count = this.getCount();
        total = this.getTotalCount();
    }
});


来源:https://stackoverflow.com/questions/15266605/ext-data-store-gettotalcount-doesnt-calculate-after-load

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!