3

私のストアは、 を呼び出したときに常に適切な量のレコードを返すとは限りませんgetTotalCount()load()この問題は、ストアの後に発生します。その時点で店舗にレコードがあることはわかっています。
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

ストアにすべてのデータが含まれている場合、ストアにロードできるレコードの数を取得するにはどうすればよいですか?


私の店舗構成。

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
            })

totalすべてのリクエストに対してプロパティが送信されていることを確認できます。

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

1 に答える 1

8

Load非同期です。それを呼び出すと、ストアは合計数のプロパティを削除し、ロード後に 2 行に到達するまでに、サーバーがまだプロパティを更新するために戻っていない可能性が最も高くなります。

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

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

あなたは本当に書くべきです:

this.grid.getStore().load({
    scope: this,
    callback: function(records, operation, success) {
        count = this.getCount();
        total = this.getTotalCount();
    }
});
于 2013-03-07T12:43:01.573 に答える