jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Need help with "clickable" checkbox
Tagged: checkbox, datagrid checkbox column
This topic contains 6 replies, has 2 voices, and was last updated by dujmovicv 12 years, 6 months ago.
-
Author
-
Hi All,
please help me to resolve this small issue : I’ve set up a checkbox field in the grid which can be clicked to check or uncheck. When the chceckbox is blank (not checked) and I click on it, the php file is executing and the database record is being changed. When I refresh the page, the changes are there (i.e. the checkbox I’ve just clicked IS checked). The function is NOT working when I want to “uncheck” the record (set value to 0 in the database). It supposed to work cause almost everything is the same, except the script needs to set a value to ‘0’ instead of ‘1’
Here’s the part of the js/php file:var source = { datatype: "json", datafields: [ { name: 'id' }, { name: 'task_name' }, { name: 'task_description' }, { name: 'task_cost_total' }, { name: 'link_to_pr_task' }, { name: 'planned_finish' }, { name: 'finished' }, { name: 'added_by' } ], id: 'id', url: '../grid/jqwidgets/controllers/tasks_on_pr_controller.php?action=<?=$action;?>', updaterow: function (rowid, rowdata) { // synchronize with the server - send update command var data = "update=true&" + $.param(rowdata); $.ajax({ dataType: 'json', url: '../grid/jqwidgets/controllers/tasks_on_pr_controller.php?action=<?=$action;?>', data: data, success: function (data, status, xhr) { // update command is executed. } }); } };
and here’s the controller php file :
if (isset($_GET['update'])){ // UPDATE COMMAND if ($_GET['finished'] == true) { $update_query_2 = "UPDATE tasks_on_project SET finished = '1' WHERE project_id = '".$project_id."' AND task_id = '".$_GET['id']."'"; } else { $update_query_2 = "UPDATE tasks_on_project SET finished = '0' WHERE project_id = '".$project_id."' AND task_id = '".$_GET['id']."'"; } $result_2 = mysql_query($update_query_2) or die("SQL Error 1: " . mysql_error()); echo $result_2;}
Please someone help me why it IS working for ‘true’ and not working ‘else’?
By the way, the datafield for ‘finished’ is like :{ text: 'Finished', datafield: 'finished', columntype: 'checkbox', width: 65 }
and it has value 1 (checked) OR 0 (not checked)
Thank you in advance!!!!!Hi dujmovicv,
What is the value of $.param(rowdata) when you uncheck the checkbox?
Do you use jQWidgets 2.5? If you do, then you are missing the last parameter of the updaterow callback function and especially the commit parameter which represents a callback function. In the ajax’s success, call commit(true), else on error, call commit(false).Best Wishes,
Peter StoevjQWidgets Team
http://www.jqwidgets.comNo, I’m using 2.4.2
Is there a way to check the value of $.param(rowdata)? Maybe in the browser console?
Thank you for helping meIn the browser console or with a simple alert. See here: http://api.jquery.com/jQuery.param/
Best Wishes,
Peter StoevjQWidgets Team
http://www.jqwidgets.comI’ve managed to retrieve the $.param(rowdata) values and now I’m even more confused…. The ‘finished’ value is passed correctly : it is ‘true’ when checked and ‘false’ when unchecked.
I modified my php to :if ($_GET['finished'] == true) { $update_query_2 = "UPDATE tasks_on_project SET finished = '1' WHERE project_id = '".$project_id."' AND task_id = '".$task_id."'";}if ($_GET['finished'] == false) { $update_query_2 = "UPDATE tasks_on_project SET finished = '0' WHERE project_id = '".$project_id."' AND task_id = '".$task_id."'";}
It does NOT work when finished=false
What am I doing wrong???May be it should be $_GET[‘finished’] == ‘true’ and $_GET[‘finished’] == ‘false’.
Best Wishes,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHeh, that was it!!!! Totally confused me that is WAS working with just true and wasn’t with false… Thanks Peter, you’re the man!
-
AuthorPosts
You must be logged in to reply to this topic.