Hello,
I have a ui grid with code to hide the destroy button if only one record left in the grid:
...
columns.Command(command => { command.Destroy().Visible("isLastRecordEmail").Text("Remove"); }).Width(200);
...
function isLastRecordEmail(e) {
return $('\#GridEmails').data('kendoGrid').dataSource.data().length > 1;
}
But if I click the Add button then a new records appears and destroy button will appear for last record to allow to delete the very last record.
My question is, how to hide the destroy button in this case?
I did try to add code:
function isLastRecordEmail(e) {
if ($('\#GridEmails').EditIndexes.Count > 0) return false;
but EditIndexes is undefined.
Could you please help?
Thanks!
7 Answers, 1 is accepted
You can resolve the issue by adding the following modification:
function isLastRecordEmail(e) { var grid = $('\#grid').data('kendoGrid'); var items = grid.items(); var count = items.length; if (count === 2 && items[0].uid === items[1].uid) { count--; } return count > 1;}I hope this will prove helpful.
Regards,
Eyup
Progress Telerik
The items[0].uid and items[1].uid are undefined in the line below. I am using version 2019.1.220 of Kendo ui mvc. FYI.
if (count === 2 && items[0].uid === items[1].uid)
In this case try the following modification to your original approach:
function isLastRecordEmail(e) { return $('\#GridEmails').data('kendoGrid').items().length > 1;}That should do the trick.
Regards,
Eyup
Progress Telerik
