Dear Abu Ghufran,
I have used your script for checkbox and everything is working fine. When I try to put the code on my application the code is not work. I do the debug in Firefox and found that the response tab is not found and html tab is empty, which means no data to edit the mysql table.
Below is the script:
<script>
// checkbox + ajax update without edit mode
function cboxFormatter(cellvalue, options, rowObject)
{
if ( cellvalue == 1 )
return '<input id="cbox'+options.rowId+'" type="checkbox" name="completed" value="'+options.rowId+'" onclick="updateRow('+options.rowId+',this.checked);" checked/> ';
else
return '<input id="cbox'+options.rowId+'" type="checkbox" name="completed" value="'+options.rowId+'" onclick="updateRow('+options.rowId+',this.checked);" /> ';
}
function cboxUnFormat(cellvalue, options, cell)
{
return $('input', cell).attr('value');
}
function updateRow(id, checked)
{
// call ajax to update date in db
var request = {};
request['oper'] = 'edit';
request['messageId'] = id;
if (checked)
request['closed'] = 1;
else
request['closed'] = 0;
var grid = $('#list1');
$.ajax({
url: grid.jqGrid('getGridParam','url'),
dataType: 'html',
data: request,
type: 'POST',
error: function(res, status) {
$.jgrid.info_dialog($.jgrid.errors.errcap,'<div class="ui-state-error">'+ res.responseText +'</div>',
$.jgrid.edit.bClose,{buttonalign:'right'});
},
success: function(data) {
// reload grid for data changes
grid.jqGrid().trigger('reloadGrid',[{jqgrid_page:1}]);
}
});
}
</script>
I think the the "url: grid.jqGrid('getGridParam','url')" is the problem.
I'm using this Referer to open my grid:
http://localhost/clients/admin/index.php?action=inbox
Do you have any suggestions.
Best regards.
Code looks ok except:
request['messageId'] = id;
It should be:
request['id'] = id;
… this id key is hardcoded in lib to identify row to edit.