Checkbox + Ajax update without edit mode

QuestionsCheckbox + Ajax update without edit mode
Azhar Abdallah asked 8 years ago

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.

2 Answers
Abu Ghufran answered 8 years ago

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.

Azhar Abdallah answered 8 years ago

Thank you Abu Ghufran

Works as expected.

regards.

Your Answer

4 + 5 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?