-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
confirmation behaviour configuration #221
base: master
Are you sure you want to change the base?
Conversation
I like the idea of popup customization. While I'm not sure about the API introduced in the PR. Let me think about it a little bit. |
|
@kirilvit, what is about setting the option |
@tabalinas it's a really good solution but looks like it don't work with async confirmation (for example we need custom dialogs). |
@atanana it's posible to make it work with async confirmations. But the code is not elegant :) confirmDeleting: false,
onItemDeleting: function (args) {
if (!args.item.deleteConfirmed) { // custom property for confirmation
args.cancel = true; // cancel deleting
confirm.showConfirm('Are you sure?', function() {
args.item.deleteConfirmed = true;
$grid.jsGrid('deleteItem', args.item); //call deleting once more in callback
});
}
}, |
@kirilvit cool! I wouldn't have guessed such solution |
Beautiful handling! I had to change the code just a bit, but the concept was the key. Thanks! |
Hello, I am trying to implement that solution. Here is my code: onItemDeleting: function (args) {
if (!args.item.deleteConfirmed) { // custom property for confirmation
args.cancel = true; // cancel deleting
var string = "The user \"" + args.item.Name + "\" will be deleted. Are you sure?";
$("#deleteDialog").dialog("open");
$("#deleteDialogText").text(string);
itemToDelete = args.item;
}
}
(...)
deleteItem: function (item) {
console.log(item);
var dataObject = {
login: item.Login
};
$.ajax({
type: 'DELETE',
url: "controllers/UsersController/",
data: dataObject,
success: function() {
$("#dg_users").jsGrid("loadData");
console.log("success");
}
});
}
(...)
$("#deleteDialog").dialog({
autoOpen: false,
width: 200,
buttons: {
"Confirm": function () {
itemToDelete.deleteConfirmed = true;
$("#dg_users").jsGrid("deleteItem", itemToDelete);
$("#dg_users").jsGrid("loadData");
$(this).dialog("close");
},
"Cancel": function () {
$(this).dialog("close");
}
}
}); It works fine, the deleteDialog open and when the user press "Confirm" the ajax request is sent and delete the item of repository. But the Jsgrid don't execute the loadData... I have to press F5 to refresh the users list of jsgrid. Anyone knows why that happen? |
backpt, I did not try the delete functionality, but this is my guess: It is possible that delete operations can be complex. For example, if you delete "red widget" from the grid, the actual delete operation might require that you delete all red widgets, and not just the one the user clicked to delete. If loading was automatic, how would jsGrid know what to load? Everything but the single, deleted record, or something less than that? You already should have loading logic for when you initialize the grid. Move your load code to a function and call it after you delete. The grid should then contain whatever data you want. I hope my guess helps. |
I have already a function to load:
How can I tell the Grid to load data from an external function? |
Put your "return $.ajax..." into a function named something like "private void loadMyData()." Then, remove the ajax from your loadData eventhandler in the jsGrid code. In its place, call your new "loadMyData()" function. You can then also call "loadMyData()" in your delete eventhandler in the jsGrid code (or wherever it is you are handling the code to delete the record). |
@JeffMatthews2 The previous code it's working good, the issue was with the users ID that I implemented. Thanks anyway! |
Another example using jsgrid and bootbox for confirmation dialog
|
I've added new callback in grid configuration. From my point of view it's pretty useful for custom dialogues or confirmation logic.
Example: