我在js / widgets / LoadAllStoreMixin.js中声明了以下mixin:
define([ 'dojo/_base/declare', 'dgrid/_StoreMixin' ], function(declare,
_StoreMixin) {
return declare(_StoreMixin, {
// summary:
// dgrid mixin which implements the refresh method to
// always perform a single query with no start or count
// specified, to retrieve all relevant results at once.
// Appropriate for grids using memory stores with small
// result set sizes.
refresh : function() {
var self = this;
// First defer to List#refresh to clear the grid's
// previous content
this.inherited(arguments);
if (!this._renderedCollection) {
return;
}
return this._trackError(function() {
var queryResults = self._renderedCollection.fetch();
queryResults.totalLength.then(function(total) {
// Record total so it can be retrieved later via
// get('total')
self._total = total;
});
return self.renderQueryResults(queryResults);
});
},
renderArray : function() {
var rows = this.inherited(arguments);
// Clear _lastCollection which is ordinarily only used for
// store-less grids
this._lastCollection = null;
return rows;
}
});
});
这与http://dgrid.io/tutorials/0.4/single_query/中编写的窗口小部件相同,允许OnDemandList加载所有内容,而不仅仅是minRowsPerPage
条记录。它被称为:
var gridDataString = dom.byId("connectedEnvironmentsAndLevelsGridData").innerHTML;
eval("var connectedEnvironmentsAndLevelsGridJsonData=" + gridDataString);
var connectedEnvironmentsAndLevelsStore = new Memory(
{ data: connectedEnvironmentsAndLevelsGridJsonData }
);
var SelectionGrid = declare([ Grid, LoadAllStoreMixin, Selection, Keyboard, DijitRegistry]);
connectedEnvironmentsAndLevelsGrid = new SelectionGrid({
store : connectedEnvironmentsAndLevelsStore,
selectionMode : "toggle",
columns : connectedEnvironmentsAndLevelsGridHeader,
allowSelectAll : true,
allowSelect: function(row) {
// disable the grid's rows basing on the phase compatibility
// if true, the row selection is enabled, otherwise disabled
return checkPhaseCompatibility(row);
}
}, "connectedEnvironmentsAndLevelsGrid");
// Grid is an OnDemandGrid, not a normal grid.
它已正确加载(因此define([], function(){});
样板文件没有问题),但出于某种原因,它会在第一个refresh()
的{{1}}中返回,因此它没有做它应该做的事情。我不知道为什么会失败。我是否需要编写代码而不仅仅是if
和refresh()
函数?
答案 0 :(得分:0)
您正在使用dgrid 0.4版本的示例,我希望您也使用相同版本的API。
在0.4版本中,store
属性已更改为collection
connectedEnvironmentsAndLevelsGrid = new SelectionGrid({
collection : connectedEnvironmentsAndLevelsStore,
selectionMode : "toggle",
columns : connectedEnvironmentsAndLevelsGridHeader,
allowSelectAll : true,
allowSelect: function(row) {
// disable the grid's rows basing on the phase compatibility
// if true, the row selection is enabled, otherwise disabled
return checkPhaseCompatibility(row);
}
}, "connectedEnvironmentsAndLevelsGrid");
更新:如果您使用的是0.3version,则帖子中的示例将无效,因为0.3版本的_renderCollection
中没有_StoreMixin
属性。此外,还缺少其他属性,如' _total`,正在此扩展中使用。
如果你能告诉我们你想要实现的目标,那么我们可以提供替代解决方案。