jqxGrid - dropdownlist的句柄源 - 显示名称,保存id

时间:2014-05-17 16:02:04

标签: jquery jqxgrid

我正在尝试使用json source中的数据在我的jqxGrid中显示一个下拉列表。

我现在的代码是(简化):

var dropDownListSource =
{
    datatype: "json",
    datafields: [
        { name: 'name' },
        { term_id: 'term_id' }
    ],
    id: 'term_id',
    url: Ajax.ajaxurl,
    mtype: 'POST',
    data: {
       action: 'get_taxonomy_terms'
    }
    };

    var dropdownListAdapter = new $.jqx.dataAdapter(dropDownListSource, { autoBind: true, async: false });



// initialize jqxGrid
    $("#jqxgrid").jqxGrid(
columns:
    [
    { text: 'Category', columntype: 'dropdownlist', datafield: 'category', width: 177,
        initeditor: function (row, cellvalue, editor) {
           editor.jqxDropDownList({ displayMember: 'name', source: dropdownListAdapter });
        }
    }
    ]           
 });

JSON是:

[{"term_id":"17","name":"category name","slug":"nova-kategorie-2","term_group":"0","term_taxonomy_id":"17","taxonomy":"budget-category","description":"","parent":"0","count":"0"}]

此代码显示下拉列表,但我需要显示名称,并保存term_id。

我该怎么做?

1 个答案:

答案 0 :(得分:1)

以下是您正在寻找的一个示例!

还有很多其他选择!但这就像你知道下拉列表源代码时内置的那样,或者你可以构建自己的源代码

http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/gridkeyvaluescolumnwitharray.htm?arctic