我试图使用dgrid例子与选择器使用内存存储,但无法填充网格,我得到一个错误TypeError :renderedCollection.fetchRange不是一个函数。请教一下,如何处理这个问题
我编辑了包括dstoreMemory。在网格中加载数据仍然有问题
require([
'dojo/_base/declare', 'dgrid/Grid', 'dgrid/Selector', 'dstore/Memory'
], function (declare, Grid, Selector, Memory) {
/* jshint maxlen: 300 */
var dataList = [
{ col1: 'normal', col2: false, col3: 'new', col4: 'But are not followed by two hexadecimal', col5: 29.91, col6: 10, col7: false },
{ col1: 'important1', col2: false, col3: 'new', col4: 'Because a % sign always indicates', col5: 9.33, col6: -5, col7: false },
{ col1: 'importan2t', col2: false, col3: 'read', col4: 'Signs can be selectively', col5: 19.34, col6: 0, col7: true },
{ col1: 'note1', col2: false, col3: 'read', col4: 'However the reserved characters', col5: 15.63, col6: 0, col7: true },
{ col1: 'normal4', col2: false, col3: 'replied', col4: 'It is therefore necessary', col5: 24.22, col6: 5.50, col7: true },
{ col1: 'important', col2: false, col3: 'replied', col4: 'To problems of corruption by', col5: 9.12, col6: -3, col7: true },
{ col1: 'note', col2: false, col3: 'replied', col4: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris', col5: 12.15, col6: -4, col7: false }
];
var employeeStore = new Memory({data:dataList, idProperty: 'col1'});
// In 0.4, Selector already inherits Selection so you don't have to
var grid = new (declare([ Grid, Selector ]))({
collection: employeeStore,
columns: {
col1: 'Column1',
col2: 'Column 2'
}
}, 'grid');
grid.startup();
});
这看起来不太像dgrid的一个例子。 你使用的是 dojo/store/Memory
但dgrid 0.4+本机支持的是 仓库,不 dojo/store
.
dstore/Memory
在功能上非常类似于 dojo/store/Memory
所以你应该可以在这个例子中使用它而不会有问题。
我在我的项目中也遇到了这个问题,请看这个例子,在Widget文件夹中添加这个widget到一个名为AttributeGrid.js的javascript文件中,然后用 "widgetAttributeGrid "加载它。
define(["dojo/_base/declare",
"dgrid/OnDemandGrid",
"dgrid/extensions/ColumnHider",
"dojo/store/Memory",
"dstore/legacy/StoreAdapter",
"dgrid/Selection"
],
function (declare,
OnDemandGrid, ColumnHider, Memory, StoreAdapter, Selection
) {
return declare(null, {
constructor: function (arg) {
debugger;
declare.safeMixin(this, arg);
},
startup: function () {
debugger;
var columns = [];
columns.push({
label: "FID",
field: "FID",
width: "auto",
});
debugger;
columns.push({
label: "PARK_NAME",
field: "PARK_NAME",
width: "auto",
});
var dataList = [
{ FID: '1', PARK_NAME: "park 1" },
{ FID: '2', PARK_NAME: "park 2" }
];
const dataStore = new StoreAdapter({
objectStore: new Memory({
idProperty: "FID"
})
});
dataStore.objectStore.data = dataList;
debugger;
var grid = new (declare([OnDemandGrid, Selection, ColumnHider
]))({
collection: dataStore,
bufferRows: Infinity,
selectionMode: 'extended',
columns: columns
}, this.gridNode)
grid.startup();
},
})
})
将这个widget添加到Widget文件夹中一个名为AttributeGrid.js的javascript文件中,然后用 "widgetAttributeGrid "加载它。
接着用
var newAttributeGrid = new AttributeGrid({
gridNode: "fdatagird"
});
'fdatagird'是Html元素的Id。
它为我工作。