网格显示空白页

时间:2013-09-06 05:57:42

标签: dojo dojox.grid.datagrid

显示空白页面...请帮助

require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/dom', 'dojox/grid/cells/dijit', 'dojo/domReady!'], function (lang, DataGrid, ItemFileWriteStore, dom)
 {

    var datalist = [{
        col1: 123,
        col2: 'X',
        col3: 'A',
        col4: 29.91,
        col5: 1,
        combo:''
    }, {
        col1:321,
        col2: 'Y',
        col3: 'B',
        col4: 9.33,
        col5: 2,
        combo:''
    }, {
        col1: 456,
        col2: 'Z',
        col3: 'C',
        col4: 19.34,
        col5: 1,
        combo: ''
    }

    ];
      var store = new ItemFileWriteStore({
        data: data
    });
    var layout = [{
        'name': 'SNO',
        'field': 'id',
        'width': '100px',
        'editable':'true'
    }, {
        'name': 'Name',
        'field': 'col2',
        'width': '100px',
        'editable':'true'
    }, {
        'name': 'Batch ',
        'field': 'col3',
        'width': '200px',
        'editable':'true'
    }, {
        'name': 'Percent',
        'field': 'col4',
        'width': '150px',
        'editable':'true'
    }, {
        'name': 'stage',
        'field': 'col5',
        'width': '150px',
            'editable':'true'
    }, {
        'name': 'combo',
        'field': 'combo',
        'width': '200px',
        'type': 'dojox.grid.cells.ComboBox',
        'options':['A','B','C'],
        'editable':true
    }];
    var grid = new DataGrid({
        id: 'grid',
        store: store,
        structure: layout,
        rowSelector: '20px'
    });
    grid.placeAt("gridDiv");
    grid.startup();
});

1 个答案:

答案 0 :(得分:0)

不知道你是否还需要答案,但是当我看到你的代码时,我认识到一件事。 您可以在datalist中定义数据数组:

var datalist = [{
    col1: 123,
    col2: 'X',
     ....
    }];

然后用数据将数据填入商店:

 var store = new ItemFileWriteStore({
    data: data
});

很明显为什么网格中没有数据,因为“数据”不存在,因此网格中不会显示任何行。

试试这样:

var datalist= { 
      identifier: 'col1',
      items: [
       { col1: 123, col2: 'X',col3: 'A',col4: 29.91,col5: 1,combo:'' },
       { col1: 321, col2: 'Y',col3: 'B',col4: 9,33,col5: 2,combo:'' },
       { col1: 456, col2: 'Z',col3: 'C',col4: 19,34,col5: 1,combo:'' },
      ]
    };

 var store = new ItemFileWriteStore({
    data: datalist
});

你的布局也有点奇怪。你没有定义“id”的字段,但你选择它来制作tableRow?!?我猜你的意思是字段“col1”而不是“id”,对吧?

必须如下:

var layout = [
            {name:"SNO", field: "col1", width:"30%", editable:true },
            {name:"Name", field: "col2", width:"30%", editable:true },
            .....// and so on
            ];

然后你可以开始填充网格。

 var grid = new DataGrid({
            id: 'grid',
            store: store,
            structure: layout,
            rowSelector: '20px'
            },"gridDiv");

            grid.startup();
           });

希望这有点帮助。

此致,Miriam

相关问题