【问题标题】:Problem regarding inserting a custom element in jqgrid关于在 jqgrid 中插入自定义元素的问题
【发布时间】:2011-04-10 01:18:32
【问题描述】:

我遵循了 jqgrid 文档中的规范,但是当我尝试保存该行时出现错误。 这里是示例代码:

<script>
function myelem (value, options) {
  var el = document.createElement("input");
  el.type="text";
  el.value = value;
  return el;
}

function myvalue(elem, operation, value) {
    if(type=='get') {
       return $(elem).find("input").val();
    } else if(type == 'set') {
       $('input',elem).val(stringvalue);
    }
}
jQuery("#grid_id").jqGrid({
...
   colModel: [ 
      ... 
      {name:'price', ..., editable:true, edittype:'custom',
       editoptions:{custom_element: myelem, custom_value:myvalue} },
      ...
   ]
...
});
</script>

在调试的以下行中,我发现类型未定义是否有任何其他方法可以知道它是值的集合还是获取。

...
if(type=='get') {
...

【问题讨论】:

    标签: jquery jqgrid


    【解决方案1】:

    您当然应该使用operation 而不是typevalue 而不是stringvalue。这似乎是 jqGrid 文档中的一个错误。您应该另外将jQuery("#grid_id").jqGrid({...}); 的代码放在jQuery(document).ready(function() {/*place your code here*/}); 处理程序中。

    如果您使用表单编辑,我建议您也阅读this answer 并使用recreateForm:true

    更新:因为 jqGrid 的文档是 wiki 文档,每个人都可以修改它,我刚才在您可能使用的文档中修改了the corresponding place

    【讨论】:

    • 我看到了操作操作数的值,但它包含单元格的名称而不是操作的类型
    • @ZeroAbsolute:我想帮助你,但你发布的信息太少。例如,不清楚您使用哪种编辑模式(表单编辑、内联编辑或单元格编辑)。每种编辑模式都有自己的代码。例如herehere 你可以看到'get' 和'set' 用于表单编辑。第二个参数在这里是正确的。您应该发布更多您使用的代码。
    • @ZeroAbsolute:在行内编辑或单元格编辑的情况下,您只需实现custom_value 的简化形式,其中第二个参数始终为“get”。可能我为the answer准备的one working example会对你有更多帮助。
    • 是的,我使用内联编辑,是的,我像你一样实现了,而且似乎运行良好。
    猜你喜欢
    • 2019-11-23
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 2019-05-08
    相关资源
    最近更新 更多