0

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?

Here is pertinent code:

{ 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;
}

Thanks, Scott

Doo Dah
  • 3,979
  • 13
  • 55
  • 74
  • I now have this instead: var rowId = jQuery('#myTable').jqGrid('getGridParam','selrow'); $("#recordingsTable").jqGrid('setCell', rowId, 'someID', newId, '', null, true); I see the data show up in the column. But, when saving the row, the data is no longer set. – Doo Dah Aug 16 '12 at 21:49

1 Answers1

0

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?

Scott

Doo Dah
  • 3,979
  • 13
  • 55
  • 74