【问题标题】:In jqGrid, is there anyway to use Ajax to get data for your custom_element?在 jqGrid 中,是否有使用 Ajax 为您的 custom_element 获取数据的方法?
【发布时间】:2011-06-26 14:32:15
【问题描述】:

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

有没有办法在列设置或 custom_element 函数中做到这一点?

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

有什么建议吗?

【问题讨论】:

    标签: jquery ajax jqgrid


    【解决方案1】:

    您可以在网格初始化期间使用任何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}});
        }
    });
    

    【讨论】:

    • 感谢您的帮助。这非常接近正确的答案,但我认为我注意到的是,如果您只设置 List,它会删除 custom_element 和 custom)_value 设置,因此您必须包含这些选项(只需在初始化中重复什么)才能得到它工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 2013-03-23
    • 1970-01-01
    相关资源
    最近更新 更多