dgrid 'Object doesn't support this action; when attempting to render columns

150 views Asked by At

I'm trying to render a grid using dgrid. When I try it throws an error when trying to create the columns. I've followed the example exactly so I can't figure out what's wrong. Any help is appreciated.

        require(["dojo", "dojo/dom", "dojo/_base/array", "dijit/registry", "dojo/store/Memory", "dgrid/Grid", "dojo/domReady!"],
       function (array, Grid, dom, dojo, registry, Memory, On) {
           var xmlhttp = new XMLHttpRequest();
           xmlhttp.open("GET", "http://localhost:5944/Home/GetData", true);
           xmlhttp.send();
           xmlhttp.onreadystatechange = function () {
               if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                   data = JSON.parse(xmlhttp.responseText);
                   GridStore = new Memory({ data: data, idProperty: "_id" });
                   CreateGrid();

               }

           }



           CreateGrid = function () {
               var columns = {
                   _id: { label: "ID" },
                   _SectionID: { label: "SpecID" },
                   _name: { label: "Name" },
                   _number: { label: "Number" },
                   _description: { label: "Description" },
                   _url: { label: "URL" }
               };

               var grid = new Grid({ columns: columns }, 'editGrid');
               grid.renderArray(GridStore);

           }

Attempt with OnDemandGrid

                   CreateGrid = function () {
                   var grid = new OnDemandGrid({
                       collection: GridStore,
                       columns: [
                          { field: "_id", label: "ID" },
                          { field: "_SectionID", label: "SpecID" },
                          { field: "_name", label: "Name" },
                          { field: "_number", label: "Number" },
                          { field: "_description", label: "Description" },
                          { field: "_url", label: "URL" }
                       ]

                   }, 'editGrid');
               }
2

There are 2 answers

0
Danger_Fox On BEST ANSWER

There was an interference with another package that I was pulling in causing the type of grid to be incorrect.

3
Ken Franqueiro On

renderArray expects to receive an array as the name suggests, not a store, so that's probably what's causing the error.

If you're using a store, then you probably want to be using either dgrid/OnDemandGrid or mixing in dgrid/extensions/Pagination, and setting the store property (assuming dgrid 0.3; if you're using 0.4, you should be using dstore and would set the collection property).

Have a look at the Grids and Stores tutorial for whichever version you're using, 0.3 or 0.4.