Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to hide edit and delete button based on the status of each record in Kendo Grid?

What I have tried:

JavaScript
function onDataBound() {
    //Selects all edit buttons
    $("#Grid tbody tr .k-grid-edit").each(function () {
        var currentDataItem = $("#Grid").data("kendoGrid").dataItem($(this).closest("tr"));
 
        //Check in the current dataItem if the row is editable
        if (currentDataItem.isEditable == true) {
            $(this).remove();
        }
 
             
    })
 
    //Selects all delete buttons
    $("#Grid tbody tr .k-grid-delete").each(function () {
        var currentDataItem = $("#Grid").data("kendoGrid").dataItem($(this).closest("tr"));
 
        //Check in the current dataItem if the row is deletable
        if (currentDataItem.isDeletable == true) {
            $(this).remove();
        }
    })
}
Posted
Updated 24-Aug-16 6:03am
v2
Comments
David_Wimbley 23-Aug-16 16:41pm    
You probably need to post some HTML so we can try your JS against the html. Right now its going to be pretty difficult to help you as we have to re-create the HTML on our own.
riteshsingh_jsr 24-Aug-16 5:29am    
Hi David,

Thanks for updating. forget all the JS please suggest what I can do for above problem.

Thanks

1 solution

The onDataBound() code seems the same from this article Hide edit and delete button based on the status of each record. - Grid - Kendo UI Forum[^] ...quoting the source is always good
JavaScript
function onDataBound(e) {
//Normally it's better to add "e", in this case you might not use it but is surely important when you're Adding or Editing a record as this helps accessing the row model details (ex: e.model.ID etc). Also you can add custom buttons to your kendo grid and would also need that.
}

For this code to work, you need to add isEditable and isDeletable or similarly named properties to your model Ex:
C#
public class MyGridModel
{
    //Create a list of MyGridModel and set these values from the server before loading data in grid
    public int ID { get; set; }
    public bool isEditable { get; set; }
    public bool isDeletable { get; set; }
    ...
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900