下载jqxgrid单元格

时间:2014-03-17 15:10:09

标签: javascript json jqxgrid

我正在尝试在Jqxgrid中填充一个包含两列的表:一个包含客户端,另一个包含一个包含组名的dropbox。

此部分成功获取要在下拉框中使用的数据。 Chrome会成功将其记录到控制台:

var groupsource =
{
    datatype: "json",
    datafields: [
        { name: 'groupname', type: 'string'},
        { name: 'groupid', type: 'integer'}
    ],
    id: 'GroupID',
    url: 'testje.php',
    cache: false,
};

这部分似乎也很好用:

var employeesAdapter = new $.jqx.dataAdapter(groupsource, {
    autoBind: true,
    beforeLoadComplete: function (records) {
        var data = new Array();
        // update the loaded records. Dynamically add EmployeeName and EmployeeID fields. 
        for (var i = 0; i < records.length; i++) {
            var employee = records[i];
            employee.GroupName = employee.groupname;
            employee.GroupID = employee.groupid;
            data.push(employee);
        }
        return data;
    }
});

然而,这部分似乎没有加载数据源吗?下拉列表中没有任何数据包含任何数据。当我登录到控制台时,似乎没有组名:

var source =
{
    datatype: "json",
    datafields: [
        { name: 'GroupName', value: 'GroupID', values: { source: employeesAdapter.records, value: 'GroupID', name: 'GroupName' } },
        { name: 'client'}
    ],
    url: 'singlesgrid_data.php',
    cache: false,
    updaterow: function (rowid, rowdata){
        // synchronize with the server - send update command
        $.ajax({
            dataType: 'json',
            url: 'singlesgrid_data.php',
            data: {'update' : 'true', 'client' : rowdata.client, 'groupid' : rowdata.groupid},
            success: function (data, status, xhr){
                // update command is executed.
            }
        });
    }
};

显然这个输出也不起作用:

var dataAdapter = new $.jqx.dataAdapter(source);        
$("#jqxgrid").jqxGrid(
{
    source: dataAdapter,
    editable: true,
    sortable: true,
    pageable: true,
    columns: [
        { text: 'Groep', datafield: 'GroupID', displayfield: 'GroupName', columntype: 'dropdownlist', width: 150},
        { text: 'client', datafield: 'client', width: 250}
    ]
});

有人能告诉我在源var中填充数据字段会出现什么问题吗?

2 个答案:

答案 0 :(得分:0)

解决方案是:

var groupsource =
        {
            datatype: "json",
            datafields: [
                { name: 'groupname', type: 'string'},
                { name: 'groupid', type: 'integer'}
            ],
            id: 'GroupID',
            url: 'testje.php',
            cache: false,
            async: false
         };

您也可以查看此示例:jQWidgets Grid DropDownList Editor 希望这会对你有所帮助。

答案 1 :(得分:0)

你有没有得到这个,我有类似的问题,但你在dataAdapter上试过autoBind: true

var dataAdapter = new $.jqx.dataAdapter(source, { autoBind: true });

这些字段中的翻译值为我的实际名称,但它没有列出网格中不存在的字段可用的任何值。

相关问题