ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: nuno.nogueira on February 10, 2014, 04:42:58 pm
-
I want to prevent users from deleting rows from a table where there are related records in another table. I'm using MySQL.
In PHP i have:
$msg=array();
if(empty($whatever)){
$msg['cenas']="N
-
In the attached file you may find my previous question, since the code was stripped off..
-
You can think of couple of ways to do this:
1) Keep a hidden boolean column which tells you whether the row has associated records.
rowData["related"] == true / false
Either don't display delete button in the row having related records or show a message when Delete button is clicked.
column.render = function(ui){
if(ui.rowData["related"]){
return "";
}
else{
return "<button>Delete</button>";
}
}
2) Check Server side after deleteList is posted. In this case you don't need jQuery.parseJSON because dataType is already "json"
obj received by success callback is constructed in PHP.
Format of obj is {related => boolean, msg => string, rows=> Array of rows }
if (deleteList.length) {
$.ajax($.extend({}, ajaxObj, {
data: { "deleteList": deleteList },
dataType:"json",
success: function (obj) {
//var obj = jQuery.parseJSON(rows);//not required.
if(obj.related){
//show message
alert(obj.msg);
$grid.pqGrid("rollback", { type: 'delete' });
}
else{
$grid.pqGrid("commit", { type: 'delete', rows: obj.rows });
}
},
complete: function (response) {
$grid.pqGrid("hideLoading");
$grid.pqGrid("rollback", { type: 'delete' });
}
}));
}
-
Solution 2 is working fine for now although I think solution 1 could be more effective (less server requests).
I'll dig into it.
Thanks!
:D