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

4 posts, 0 answers
  1. suman
    suman avatar
    2 posts
    Member since:
    Dec 2016

    Posted 15 Dec 2016 Link to this post

    Hi, I need to disable excel export button if row count is zero. or show pop up "Now records found" then prevent download.
  2. Patrick
    Admin
    Patrick avatar
    206 posts

    Posted 16 Dec 2016 Link to this post

    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.
  3. suman
    suman avatar
    2 posts
    Member since:
    Dec 2016

    Posted 16 Dec 2016 in reply to Patrick Link to this post

    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?
  4. Patrick
    Admin
    Patrick avatar
    206 posts

    Posted 16 Dec 2016 Link to this post

    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.
Back to Top