1

In my grid I'm using custom formatter to edit one of its column field values.

I want set the focus to that editable field on selecting the row of the grid.

please help me on this...

This is my grid

jQuery("#myGrid").jqGrid({
datatype: "local",
colNames:['','','',''],
colModel:[{name:'id',index:'id', width:50, hidden:true},
          {name:'activname',index:'activname', width:100, title: false},
          {name:'formattedvalue',index:'formattedvalue', width:200, formatter:formatField},
          {name:'value',index:'value', hidden:true}],
height: window.innerHeight - 318,

onSelectRow: function(id,stat,e)
{
  // here I want to set the focus to the editable field
}});

and This is the formatter function

function formatField(cellvalue, options, rowObject){
 jQuery("myGrid").jqGrid('setColProp','formattedvalue',
  {editable: true, 
   edittype:"custom", 
   editoptions: {
     custom_element: function(value, options) {

       var elemStr = '<div><input type="text" id="'+ options.id +'_id" tabindex="2" maxlength="10" size="10" value="' + value + '" /> </div>';          

       var $custElem = jQuery(elemStr);

       $custElem.find("input").bind("keydown",function(e) {             
         return dynamicFieldKeyPressed(e, this, rowObject);                         
       });

       return $custElem[0];
     },
     custom_value: function(elem, operation, value){           
         return jQuery(elem).find("input").val();           
     }
  }
});
return cellvalue;}
idsTech
  • 147
  • 2
  • 14

1 Answers1

0

You can use

UPDATED:

   onSelectRow: function(id,stat,e){
 if(id && id!==lastSel){ 
    jQuery('#myGrid').restoreRow(lastSel); 
    lastSel=id; 
 }
 jQuery('#myGrid').editRow(id, true); 
 $("#"+id+"_formattedvalue").focus();

  },

Not tested but should work

Kris
  • 1,882
  • 1
  • 20
  • 23
  • Thank you for answering... Actually my case is bit complex than this.. I have different type of fields (text, radio, select, textarea and more) with different ids.. So I managed with something like this.. 'jQuery('input[id*="'+id+'_formattedvalue"], select[], textarea[]').focus();' – idsTech Feb 12 '13 at 09:13