0

I'm working with JQGrid PHP version 4.4.0 where i must have a checkbox as one of the column for each row which specifies status of the row. The database are being retrieved from phpmyadmin thru json. For now i retrieve the status as active and inactive. I want to add a checkbox instead of showing active/inactive in status column. If the status is active. then by default the checkbox must be checked whereas if the status is inactive. then the checkbox must be unchecked. Whenever user clicks on the checkbox it must update the status on database too.

JQgrid checkbox onclick update database

I found this answer but i don't know the way to add in to my code.

Any help is much appreciated.. Thanks

Community
  • 1
  • 1
gana
  • 11
  • 4
  • Add checkbox in your json ? – xNeyte May 05 '15 at 09:05
  • no. not adding checkbox in json.. im retrieveing data using json datatype and display as a table form.. Status is one of the column where it does show whether the status is active or inactive. I want to change that column display as checkbox – gana May 05 '15 at 09:36
  • I understood, I'm just saying you can add checkbox in your json_encoding and check it (or no) regarding its status – xNeyte May 05 '15 at 09:39
  • yup. i can do that. But, i cant update the data onclick checkbox. I'm having problem in passing data to server, i guess. – gana May 05 '15 at 09:48
  • any sample code? or any tutorial i can refer to? Thanks a lot. – gana May 05 '15 at 09:49
  • If you want help on your code, post it ! – xNeyte May 05 '15 at 09:53
  • And yes, you can update with onlick even if you generate checkbox, you will just have to add 'onclick='function(id);' in your encoding, so you can make an ajax request with the id which is in parameter – xNeyte May 05 '15 at 09:54
  • $grid->setColProperty('Status',array("name"=>"enbl","index"=>"enbl","formatter"=>"checkbox", "editoptions"=>array("value"=>"1:0"), "formatoptions"=>array("disabled"=>false))); $getColumnIndexByName = <<< BEFORESHOW function(grid, columnName) { var cm = grid.jqGrid('getGridParam', 'colModel'), i, l; for (i = 0, l = cm.length; i < l; i += 1) { if (cm[i].name === columnName) { return i; // return the index } } return -1; } BEFORESHOW; – gana May 05 '15 at 12:14
  • $loadComplete = <<< LOADCOMPLETE function () { var iCol = getColumnIndexByName ($(this), 'enbl'), rows = this.rows, i, c = rows.length; for (i = 0; i < c; i += 1) { $(rows[i].cells[iCol]).click(function (e) { var id = $(e.target).closest('tr')[0].id, isChecked = $(e.target).is(':checked'); alert('clicked on the checkbox in the row with id=' + id + '\nNow the checkbox is ' + (isChecked? 'checked': 'not checked')); }); } } LOADCOMPLETE; – gana May 05 '15 at 12:15
  • Still not able to call the checked row... – gana May 05 '15 at 12:15
  • Edit your post with code, it is unreadable in comment – xNeyte May 05 '15 at 12:23
  • @xNeyte you can check on this [link](http://stackoverflow.com/questions/30066018/jqgrid-php-onclick-update-status-in-database) – gana May 06 '15 at 08:19

0 Answers0