jqgrid autocompete更改另一列 [英] jqgrid autocompete change another column

查看:67
本文介绍了jqgrid autocompete更改另一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一列具有自动完成功能的列,可以进行内联编辑.没问题.问题在于自动完成功能具有需要设置的基础ID.我的想法是在网格中有一个隐藏的列,并使用自动完成功能的select回调来设置ID.在回调中一切看起来都不错.但是,当需要保存行时,该列为空.有什么想法会取消行数据吗?

I have a column with an autocomplete st up for inline editing. No problem there. The problem is that the autocomplete has an underlying ID that needs to be set. My thought was to have a hidden column in the grid and use the select callback of the autocomplete to set the ID. All looks good in the callback. But, when it comes time to save the row, the column is empty. Any ideas what is unsetting the row data?

以下是相关代码:

{ name: 'fieldName', label: 'fieldLabel', index: 'fielindex', width: 300,
  sortable: true, editable: true, edittype : 'custom',                          
  editoptions: {
     custom_element : someAutoComplete_element,
     custom_value   : someAutoComplete_value
  }
},
{ name:'someID', index:'someID', width: 70, hidden: true, editable: true,
  editrules: {edithidden:false} 
},

function someAutoComplete_value(elem, op, value) {  
    if (op == "set") {
        $(elem).val(value);
      }
      return $(elem).val();
}


function someAutoComplete_element,(value, options) {
    var $ac = $('<input type="text"/>');
    $ac.autocomplete( {
        source: function(request, response) {
            $.ajax({
                  // Code to deal with fetching the autocomplete
                  });
               },
        select: function(event, ui) {
               var newId = ui.item.obj.id;

               var rowId = jQuery('#myTable').jqGrid('getGridParam','selrow');
               if (rowId) {
                  var rowData = jQuery('#myTable').getRowData(rowId);
                  rowData['someID'] = newId;
               }
             }
           }
         )
return $ac;
}

谢谢, 斯科特

推荐答案

jqGrid setCell实际上将单元格设置为给定的值.如果给定的值不是HTML,则当我们去保存行时,将无法正确检索数据.我本来希望像setCellData这样的方法能够做到这一点.取而代之的是,这就是我解决问题的方法.归根结底,我要做的就是记住所选字符串的ID,以便我可以在保存时正确地将其持久保存在服务器端.

jqGrid setCell literally sets the cell to the value given. If the value given is not HTML, then, when we go to save the row, the data is not retrieved correctly. I would have expected a method like setCellData to do this. Instead, this is what I did to solve my problem. At the end of the day, all I am doing is remembering the ID of the string chosen so that I can persist it correctly server side at save time.

var newId = ui.item.obj.id;                  
var rowId = jQuery('#myTable').jqGrid('getGridParam','selrow');

if (rowId) {                      
   var rowData = jQuery('#myTable').getRowData(rowId);                      
   var newCellHTML = $(rowData['utteranceID']).attr("value", newId).get(0).outerHTML;                      
   $("#myTable").setCell(rowId, 'myColumnName',  newCellHTML);
}

这真的感觉很像我在漏东西吗?

This really feels like a hack Am I missing something?

斯科特

这篇关于jqgrid autocompete更改另一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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