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

how to disable excel export button in kendo UI if row count in grid is 0

3 Answers 1186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
suman
Top achievements
Rank 1
suman asked on 15 Dec 2016, 09:32 PM
Hi, I need to disable excel export button if row count is zero. or show pop up "Now records found" then prevent download.

3 Answers, 1 is accepted

Sort by
0
Patrick | Technical Support Engineer, Senior
Telerik team
answered on 16 Dec 2016, 06:11 PM
Hi Suman,

In order to disable exporting when there are no records in the Kendo DataSource, use the excelExport event.  It will fire when the user clicks on the export button.  Then, check to see the total amount of items in the dataSource.  Finally, use e.preventDefault() to prevent exporting.  Optionally, you can add the alert.
excelExport: function(e){
              var grid = $("#grid").data("kendoGrid");
              if (grid.dataSource.total() == 0){
                e.preventDefault();
                alert("No Records Found");
              }      
            },

For setting a message when there are no records:


Set the NoRecords property to true to display a message.  If you want to customize this message, set the messages.noRecords property.
$("#grid").kendoGrid({
            ...
            noRecords: true,           
            messages:{
              noRecords: "No Records Found"
            },
            ...
          });

Please take a look at the following Kendo UI Dojo by Progress to see the above approaches.

I hope this helps!

Regards,
Patrick
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
suman
Top achievements
Rank 1
answered on 16 Dec 2016, 06:58 PM
Thank you Patrick for quick reply. I created excelExport event to show alert and used preventdefault. Only problem is alerting twice. Any idea why its showing alert twice?
0
Patrick | Technical Support Engineer, Senior
Telerik team
answered on 16 Dec 2016, 10:49 PM
Hello Suman,

I was unable to replicate this issue.  Please create a dojo or update the one from the last post replicating the behavior.  

I look forward to your reply.

Regards,
Patrick
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
suman
Top achievements
Rank 1
Answers by
Patrick | Technical Support Engineer, Senior
Telerik team
suman
Top achievements
Rank 1
Share this question
or