jqGrid的 - 根据*初始*列值如何设置自定义editoptions? [英] jqGrid - How to set custom editoptions based on *initial* column values?

查看:4844
本文介绍了jqGrid的 - 根据*初始*列值如何设置自定义editoptions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是开源的jqGrid的插件与EF4和ASP.NET Web窗体。我需要基于从DB列值内联编辑网格行中设置的输入元件。例如,第一行可能包含一个DDL,第二行可​​能包含一个复选框等

I am using the open source jqGrid plugin with EF4 and ASP.NET Web Forms. I need to set an input element in an inline-editable grid row based on a column value from the DB. For example, the first row could contain a DDL, the second row could contain a checkbox, etc.

我试图做到这一点使用 custom_element custom_values​​ ,就像这样:

I'm trying to achieve this using the custom_element and custom_values, like so:

$("#grid1").jqGrid({
    url: 'Default.aspx/getGridData',
    datatype: 'json',
    ...
    colModel: [
    ...
    //contains the input type ('select', etc.)
    { name: 'InputType', hidden:true }, 
    ...
    //may contain a string of select options ('<option>Option1</option>'...)
    { 
      name: 'Input', 
      editable:true, 
      edittype:'custom', 
      editoptions:{
         custom_element: /* want cell value from InputType column here */ , 
         custom_value:   /* want cell value from Input column here */ 
      } 
     }, 
    ...
    ]
});

文档说,我可以打电话自定义功能设置 custom_element custom_values​​ ,但我不知道怎样才能捕捉到列中的值,并将其传递到我的自定义功能。

The jqGrid docs say that I can call custom functions to set custom_element and custom_values, but I don't see how I can capture column values and pass them into my custom functions.

有关设置 custom_values​​ ,我也注意到<一href=\"http://stackoverflow.com/questions/4987123/in-jqgrid-is-there-anyway-to-use-ajax-to-get-data-for-your-custom-element\">Oleg's很好的解决方案使用清单:参数,但是这似乎涉及额外的Ajax调用。我想避免这种情况,因为我已经拥有了所有的数据,我从最初的Ajax调用网格所需要的。

For setting custom_values, I did notice Oleg's nice solution using the list: parameter, but that appeared to involve an extra Ajax call. I want to avoid this, as I already have the all data I need from the initial Ajax call for the grid.

在总结,我需要做以下,而在在线编辑方式:

In summary, I need to do the following while in inline-edit mode:


  1. 动态分配从DB值的输入型

  2. 动态地从一个数据库字符串指定的输入值(DDL或复选框)

我也开到跳绳使用 custom_element custom_values​​ ,但后来我还是面临同样的问题动态设置 edittype editoptions:{值:} 参数

I am also open to skipping the use of custom_element and custom_values, but then I still face the same problem of dynamically setting the edittype and editoptions:{value:} parameters.

这是如何做到这一点任何想法?有,我应该采取不同的方法?

Any ideas on how to do this? Is there a different approach that I should be taking?

更新:谢谢你的努力来帮助我。每个请求的,这里是我的JSON响应的缩写例如:

UPDATE: Thanks for your efforts to help me out. Per request, here is an abbreviated example of my JSON response:

{"d":[
{"Input":null,"InputType":"select"},
{"Input":"From downtown, proceed west on Interstate 70.", "InputType":"text"}
]}

使用此数据,我想显示一个空选择一列,并且接下来的行中的一个填充的文本字段。无论是在线编辑。

With this data, I would want to show an empty select in one row, and a populated text field in the next row. Both would be editable inline.

SOLUTION :我为了找到确实的解决方案返回到这个问题的不可以涉及使用 custom_element custom_values​​ 。这里是我的解决方案(基于接受的答案下面)不断变化的 edittype editoptions

SOLUTION: I have returned to this problem in order to find a solution that does not involve using custom_element and custom_values. Here is my solution (based on the accepted answer below) to changing edittype and editoptions :

loadComplete: function () {
    var rowIds = $("#grid1").jqGrid('getDataIDs');

    $.each(rowIds, function (i, row) {
       var rowData = $("#grid1").getRowData(row);

       if (rowData.InputType == 'select') {
          $("#grid1").jqGrid('restoreRow', row);
                var cm = $("#grid1").jqGrid('getColProp', 'Input');
                cm.edittype = 'select';
                cm.editoptions = { value: "1:A; 2:B; 3:C" };
                $("#grid1").jqGrid('editRow', row);
                cm.edittype = 'text';
                cm.editoptions = null;
       }
   });
}

诺塔Bene的:对我来说一个重要的事情是记住设置 editoptions ,要求在 editrow 。此外,如在奥列格的评论中提到,避免了使用自定义元素可以让我实现日期选择器输入,无需额外的麻烦。这是我的应用程序很重要,所以我最终接受奥列格的答案,但我仍然upvoted沃尔特的答案,以及。如果这是不好的形式,我真诚地道歉。我只是想奖励那些工作最适合我的解决方案。

Nota Bene: One important thing for me was remembering to set the editoptions back to null, after calling editrow. Also, as Oleg mentioned in the comments, avoiding the use of custom elements allows me to implement datepicker inputs without extra trouble. This was important for my app, so I ended up accepting Oleg's answer, but I still upvoted Walter's answer, as well. If this is bad form, I sincerely apologize. I simply wanted to reward the solution that worked best for me.

推荐答案

如果您使用倾斜的编辑可以直接在某处你code调用 editRow 方法。在 editRow 方法从 colModel ,这都涉及到编辑的所有选项,将检查和使用。因此,您可以动态地更改任何选项编辑 edittype editoptions 。 <一href=\"http://stackoverflow.com/questions/4307147/jqgrid-how-to-make-a-column-editable-in-the-add-dialog-but-not-during-inline-e/4308172#4308172\">The回答展示了一种如何更改编辑属性。以同样的方式,你可以更改任何其他属性。

If you use incline editing you call editRow method somewhere directly in your code. Inside of the editRow method all options from the colModel, which are related to editing, will be examined and use. So you can change dynamically any options like editable, edittype or editoptions. The answer shows how one can change editable property. In the same way you can change any other properties.

如果你愿意,你可以设置有关编辑类型和选项 loadComplete 事件句柄内的信息。它具有重新present从服务器发送的原始数据数据参数。所以,你可以和其他资料,并设置编辑 edittype editoptions <扩展数据/ code>基于信息的列。

If you want you can set the information about editing type and option inside of loadComplete event handle. It has data parameter which represent the original data sent from the server. So you can extend the data with and other information and set editable, edittype or editoptions for any columns based on the information.

这篇关于jqGrid的 - 根据*初始*列值如何设置自定义editoptions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆