Search code examples
angularangular6kendo-gridexport-to-excel

How to Display No Data for Export Alert when there is no data found Angular 6 kendo-excelexport Component


Below is the code :i used angular 6 kendo-excelexport ^4.5.0 version component.

<kendo-excelexport [data]="excelDataToExport" [collapsible]="true" fileName="Sample.xlsx" #excelexport>
                <kendo-excelexport-column field="taxMonth" title="Month" [width]="200">
                </kendo-excelexport-column>
                <kendo-excelexport-column field="clientName" title="Client Name" [width]="200">
                </kendo-excelexport-column>
                <kendo-excelexport-column field="alertType" title="Alert Type" [width]="200">

                <kendo-excelexport-column field="Description" title="Description" [width]="200">
                </kendo-excelexport-column>

</kendo-excelexport>

Solution

  • Check the length of excelDataToExport if it is an array. If the length is greater than 0, download the excel sheet else show an alert.

    To achieve this, use conditional expression on the click event of the export button.

    Please find the working example: Demo

    In the example comment/uncomment the data in product.ts file to see the no data alert / download excel respectively.