使用选择器时的Dgrid错误-renderedCollection.fetchRange不是函数

时间:2016-01-22 23:10:41

标签: javascript dojo dgrid

我试图将dgrid示例与使用内存存储的选择器一起使用而无法填充网格,我收到错误TypeError:renderedCollection.fetchRange不是函数。请告知,如何解决这个问题

我编辑过包含dstore / Memory。在网格中加载数据仍有问题

 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();

});

2 个答案:

答案 0 :(得分:3)

这看起来不像dgrid的例子。您使用的是dojo/store/Memory,但dgrid 0.4+原生支持dstore,而非dojo/store

dstore/Memory在功能上与dojo/store/Memory非常相似,因此您应该能够在没有问题的情况下使用此示例。

答案 1 :(得分:0)

我的项目遇到了这个问题。 看到这个例子。

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();



        },




    })
})

将此小部件添加到小部件文件夹中名为AttributeGrid.js的JavaScript文件中。 并通过“ widget / AttributeGrid”加载它,

然后再使用

 var newAttributeGrid = new AttributeGrid({

       gridNode: "fdatagird"

      });

'fdatagird'是HTML元素的ID

对我有用。