Running dojo dgrid : subrows is undefined

流过昼夜 提交于 2019-12-11 20:05:57

问题


I have tried implementing a class for a grid layout using dgrid (using their sample), but I get this error when loading my grid (subRows is undefined). My code looks something like this:

define([
    "dojo/_base/declare",
    "dojo/_base/lang",
    "dgrid/Grid",
    "dgrid/Keyboard", 
    "dgrid/Selection"
], function(
    declare,
    lang,
    Grid,
    Keyboard, 
    Selection
){

    return declare([Grid, Keyboard, Selection], {

            columns: {
                first: "First Name",
                last: "Last Name",
                age: "Age"
            },
            selectionMode: "single", // for Selection; only select a single row at a time
            cellNavigation: false, // for Keyboard; allow only row-level keyboard navigation

         constructor: function() {
              var data = [
            { first: "Bob", last: "Barker", age: 89 },
            { first: "Vanna", last: "White", age: 55 },
            { first: "Pat", last: "Sajak", age: 65 }
            ];

            this.renderArray(data);
        }
    });
});

And calling/creating it like this,

app.gridLayout = new GridLayout().placeAt(document.body);

回答1:


Place your constructor code into postCreate method:

return declare([Grid, Keyboard, Selection], {

    columns: {
        first: "First Name",
        last: "Last Name",
        age: "Age"
    },

    selectionMode: "single",
    cellNavigation: false,

    postCreate: function() {
        var data = [
            { first: "Bob", last: "Barker", age: 89},
            { first: "Vanna", last: "White", age: 55},
            { first: "Pat", last: "Sajak", age: 65}
        ];

        this.renderArray(data);
    }
});

Also note dgrid is not dijit to minimize its dependencies and therefore it has not placeAt() method. You have two options here:

  1. Provide DOM node or id string of a placeholder to the contructor as a 2nd parameter:

    var gridLayout = new GridLayout({}, "placeholder");
    
  2. Make dgrid to be a dijit via subclassing dijit/_WidgetBase to use gridLayout.placeAt("placeholder"):

    declare([_WidgetBase, Grid, Keyboard, Selection], {});
    


来源:https://stackoverflow.com/questions/11090233/running-dojo-dgrid-subrows-is-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!