Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
60
rated 0 times [  63] [ 3]  / answers: 1 / hits: 34593  / 12 Years ago, fri, january 25, 2013, 12:00:00

I want to execute an action when click event of a delete button in a grid is done. How can I know when is clicked in Javascript?


More From » jquery

 Answers
2

(Read IMPORTANT at the end)



Use:



$(tr .k-grid-delete, #grid).on(click, function(e) {
alert(deleted pressed!);
})


Where #grid is the id of your grid.



If you want to know the data item you can do:



var item = $(#grid).data(kendoGrid).dataItem($(this).closest(tr));


Alternatively, you can define the command in the grid.columns as:



{
command: [
edit,
{
name : destroy,
text : remove,
click: myFunction
}
],
title : Commands,
width : 210px
}


where myFunction is:



function myFunction(e) {
alert(deleted pressed!);
var item = $(#grid).data(kendoGrid).dataItem($(this).closest(tr));
// item contains the item corresponding to clicked row
}


IMPORTANT: You might want to define you own destroy button where only the styling is copied from the original one (no other actions / checks). If so define your grid.columns.command as:



{
command: [
edit,
{
name : destroy,
text : remove,
className: ob-delete
}
],
title :  ,
width : 210px
}


and then define:



$(document).on(click, #grid tbody tr .ob-delete, function (e) {
e.preventDefault();
alert(deleted pressed!);
var item = $(#grid).data(kendoGrid).dataItem($(this).closest(tr));
// item contains the item corresponding to clicked row
...
// If I want to remove the row...
$(#grid).data(kendoGrid).removeRow($(this).closest(tr));
});

[#80626] Thursday, January 24, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
chase

Total Points: 78
Total Questions: 106
Total Answers: 93

Location: Comoros
Member since Tue, Mar 14, 2023
1 Year ago
chase questions
Thu, Mar 31, 22, 00:00, 2 Years ago
Thu, Jul 1, 21, 00:00, 3 Years ago
Sat, Dec 12, 20, 00:00, 4 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
;