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

Excel Export and PDF buttons disabled with now records

2 Answers 349 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Reid
Top achievements
Rank 2
Reid asked on 17 Feb 2019, 08:16 PM
How can we disable the Excel and PDF grid toolbar buttons if there is no record count?

2 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetomir
Telerik team
answered on 20 Feb 2019, 03:57 PM
Hi Reid,

In order to make some buttons within the grid's toolbar disabled, refer to the code snippets below:

1. Subscribe to the dataBound event of the grid:

.Events(ev=>ev.DataBound("onDataBound"))

2. Access the buttons within the toolbar and add the "k-state-disabled" class. This would make them appear disabled and will prevent the user from clicking them.

.ToolBar(toolbar=> {
    toolbar.Excel();
    toolbar.Pdf();
})

<script>
    function onDataBound(e) {
        if (!e.sender.dataSource.total()) {
            $(".k-grid-toolbar a.k-grid-excel").addClass("k-state-disabled");
            $(".k-grid-toolbar a.k-grid-pdf").addClass("k-state-disabled");
        }
    }
</script>

Let me know in case there is a need for additional clarifications.


Kind regards,
Tsvetomir
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
Reid
Top achievements
Rank 2
answered on 21 Feb 2019, 02:52 PM
Thank you for that.
Tags
Grid
Asked by
Reid
Top achievements
Rank 2
Answers by
Tsvetomir
Telerik team
Reid
Top achievements
Rank 2
Share this question
or