在jqGrid中,有没有使用Ajax来获取custom_element的数据?

时间:2011-02-13 21:48:03

标签: jquery ajax jqgrid

我正在做一些事情similar to this question,其中我有一个复选框列表作为自定义编辑控件。不同之处在于我想从服务器获取我的列表(不是在客户端使用 Check1,Check2,Check3 进行硬编码。

有没有办法在列设置或 custom_element 功能中执行此操作?

我似乎需要类似于您用于选择项的 dataUrl 属性,但这似乎只适用于选择项(而不是自定义项)。

有什么建议吗?

1 个答案:

答案 0 :(得分:2)

您可以在网格初始化期间使用任何list选项(准确editoptions),然后使用从服务器加载的实际数据覆盖该值:

$("#list").jqGrid({
    colModel: [
        {name:'MyMultiCheck',edittype:'custom',
         editoptions:{custom_element:MultiCheckElem,
                      custom_value:MultiCheckVal,list:''}
        }
        ...
    ]
    ...
});
$.ajax({
    url:"getMultiCheckList",
    // any other parameters like dataType:'json',
    // type: 'POST' (default type is 'GET') which depend on the server
    success: function(data){
        // the code here depend on the format of data returned from the server
        // in the simplest situation we have as data already the comma-separated
        // string which we need as a value for the list parameter so we can do
        jQuery("#list").setColProp('MyMultiCheck',{editoptions:{list:data}});
    }
});