I have a very simple setup, a grid called #list with a datasource populated with records to display.
I have a button on each row with an onClick event that calls this function:
// Soft-Delete person
var processURL = crudServiceBaseUrl + '?method=deletePerson';
function deletePerson(id){
if (confirm('#getResource("person.detail.confirmdel")#')) {
$.ajax({
type: 'POST',
url: processURL,
data: {
PERS_KY: id
},
success: function (data){
var thingToDelete = "tr:eq("+id+")";
var grid = $("#list").data("kendoGrid");
grid.removeRow(thingToDelete);
},
error: function (xhr, textStatus, errorThrown){
alert("Error while deleting person"+ "\n"+ xhr + "\n"+ textStatus + "\n" + errorThrown);
}
});
}
}
The server-side stuff works fine, the interaction with the database is good. However, the row does not disappear from the grid.
Anyone?
==============================================================================
In answer to the comments below, here is the revised function:
var processURL = crudServiceBaseUrl + '?method=deletePerson';
function deletePerson(id, row){
if (confirm('#getResource("person.detail.confirmdel")#')) {
$.ajax({
type: 'POST',
url: processURL,
data: {
PERS_KY: id
},
success: function (data){
var thingToDelete = row;
var grid = $("#list").data("kendoGrid");
grid.removeRow(thingToDelete);
},
error: function (xhr, textStatus, errorThrown){
alert("Error while soft-deleting person"+ "\n"+ xhr + "\n"+ textStatus + "\n" + errorThrown);
}
});
}
}
This all works fine, the database is populated and grid.removeRow() makes the row fade out, but then the page reloads, which I don't want.
Any idea how to stop the page reloading?
The grid already supports create, update and deleting of records. You should not try to implement it on your own.
You need to define destroy on your datasource like here
Also you can turn on a delete confirmation
EDIT: In order to conditionally show delete buttons you can hook up the DataBound-Event of the grid. You also need some indication wheter or not to show the button. I used a property called HideButton in my example. Maybe you have to adjust the class .k-grid-delete the rest should work.
below code show how to delete rows using custom delete command.
Hope this may help