我以前使用的是下面的代码。这样,在请求标头中添加了range(Say:range:items:0-49)并基于该数据获取数据。见下文:
require(["dojo/_base/declare",
"dgrid/Grid",
"dojo/store/Memory",
"dgrid/extensions/Pagination",
"dgrid/extensions/ColumnResizer",
"dgrid/extensions/ColumnHider",
"dgrid/extensions/ColumnReorder",
"dojox/data/QueryReadStore",
"dgrid/extensions/DijitRegistry",
"dojo/store/JsonRest",
"dojo/store/util/QueryResults",
"dgrid/editor",
"dojo/store/Cache",
],
function(declare, Grid, Memory, Pagination, ColumnResizer, ColumnHider, ColumnReorder, QueryReadStore, DijitRegistry, JsonRest, QueryResults, editor,Cache){
var Store = new Cache( JsonRest({
target: "/path/to/service",
query: function(query, options) {
var results = this.inherited(arguments);
var total;
var deferred = results.then(function(result) {
total = result.numRows;
return result.listOfItems;
});
var qr = new QueryResults(deferred);
qr.then(function(qr){
qr.total= total;
});
return qr;
}
}), new Memory() );
var searchGrid = new (declare([Grid, Pagination, Selection, ColumnReorder, ColumnResizer, ColumnHider, DijitRegistry]))({
store: Store,
noDataMessage: "No data found",
pageSizeOptions: [10, 15, 25],
rowsPerPage:10,
}, "searchGrid");
searchGrid.startup();
我已经将dgrid升级到0.4。,它使用dstore并且仅支持collection属性。 所以我用dstore替换了dojo / store,并使用dstore / RequestMemory与 dgrid / OnDemandGrid”。
var Store = new RequestMemory({
target: "/path/to/service",
});
var searchGrid = new (declare([Grid, Pagination, Selection, ColumnReorder, ColumnResizer, ColumnHider, DijitRegistry, selector, editor]))({
collection: Store,
noDataMessage: "No data found",
pageSizeOptions: [10, 15, 25],
rowsPerPage:10,
}, "searchGrid");
searchGrid.startup();
dstore / RequestMemory实际上更多是一次请求。因此,当网格的记录少于1000条时,它便可以正常工作。但是对于超过2000条记录,获取记录需要花费大量时间。 我想使用dstore添加相同的查询方法。我的意思是如何使用dgrid 0.4更新/替换此查询方法。 请提出建议。谢谢!