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

Hide/Disable the Destroy butons on Add/Edit in all rows

7 Answers 507 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrey
Top achievements
Rank 1
Veteran
Andrey asked on 20 Jun 2019, 01:04 PM

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

Sort by
0
Andrey
Top achievements
Rank 1
Veteran
answered on 20 Jun 2019, 03:24 PM
I've attache two images to help understanding my problem.
0
Eyup
Telerik team
answered on 24 Jun 2019, 01:01 PM
Hello Andrey,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Andrey
Top achievements
Rank 1
Veteran
answered on 24 Jun 2019, 04:01 PM
Perfect! Thank you so much!
0
Andrey
Top achievements
Rank 1
Veteran
answered on 24 Jun 2019, 04:09 PM

Hi Eyup,

but now the destroy button will be hidden for two records as well. I've attached the image.

0
Andrey
Top achievements
Rank 1
Veteran
answered on 24 Jun 2019, 04:33 PM

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)

0
Eyup
Telerik team
answered on 25 Jun 2019, 08:24 AM
Hello Andrey,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Andrey
Top achievements
Rank 1
Veteran
answered on 25 Jun 2019, 01:05 PM
Works fine! Thank you so much!
Tags
Grid
Asked by
Andrey
Top achievements
Rank 1
Veteran
Answers by
Andrey
Top achievements
Rank 1
Veteran
Eyup
Telerik team
Share this question
or