Thursday, January 26, 2012

jqGrid jquery - dynamic Caption with input textbox

when defining the jqgrid, set a variable to the option, caption, like following:

caption: myCaption,

then, whenever you want to set your caption, make html statement to the caption variable, myCaption; in the example I even try to make an input to the caption for another purpose.


e.g.
var data = $('#grid1').jqGrid('getRowData',1);    
myCaption = 'Customer ID: '+data.customer_id+'<br>';
myCaption = myCaption+'Name: <input id="icname'" type="text" value="'+data.cname+'" />';

finally, set the caption by the jqgrid method, setCaption.

$('#grid1').jqGrid('setCaption',myCaption);

for capturing the change of the input, you need to bind a change event to the input element with jquery .on function.

$('#gview_grid1').on('change','#icname', function() {
     alert( $(this).val() );
}

No comments: