This is a migrated thread and some comments may be shown as answers.

Display Edit/Delete button based on record column

2 Answers 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 16 May 2013, 11:09 AM
Hi,

If I want to display edit and delete button for the record which CanEdit column is true, can you suggest how to do that?

columns.Bound(p => p.CanEdit).Width(100);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);

Thanks
Dan

2 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 16 May 2013, 12:31 PM
Hello Dan,


To achieve this in an Ajax bounded Grid you should bind to the dataBound event and add a custom class, to the rows, that will not be editable.
E.g.
.Events(e => e.DataBound("dataBound"))

function dataBound(e) {
    var gridData = this.dataSource.view();
    for (var i = 0; i < gridData.length; i++) {
        var currentUid = gridData[i].uid;
        if (gridData[i].CanEdit == false) {
            var currenRow = this.table.find("tr[data-uid='" + currentUid + "']");
            $(currenRow).addClass("notEditable");
        }
    }
}

and then hide the edit and delete buttons via CSS
E.g.
.notEditable .k-grid-edit
{
    display: none;
}
 
.notEditable .k-grid-delete
{
    display: none;
}

 

All the best,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Dan
Top achievements
Rank 1
answered on 17 May 2013, 03:19 AM
Hi Dimiter.

Thank you so much. 
It works very well except the css - edit button cannot hide.

But by adding this, it works as expected.
.notEditable {    display: none;}  

Thanks again
Dan

Tags
Grid
Asked by
Dan
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Dan
Top achievements
Rank 1
Share this question
or