Export jon file when will support in toolbar in syncfusion

in toolbar if i click specific record and click on export button the file will be exported in json format and file contain selected row only.


1 Reply

SK Sujith Kumar Rajkumar Syncfusion Team August 3, 2021 09:16 AM UTC

Hi Sunil, 
 
Greetings from Syncfusion support. 
 
As previously updated in this forum, your requirement of exporting only the selected record in Grid on toolbar button click can be achieved by providing the selected records JSON data as custom data source to the excel export or pdf export properties as demonstrated in the below code snippet, 
 
// Grid’s toolbarClick event handler 
toolbarClick(args: ClickEventArgs): void { 
    if(args.item.text === "PDF Export") { 
        // Retrieves selected record JSON data  
        var selectedRecords = this.grid.getSelectedRecords(); 
        if (selectedRecords.length !== 0) { 
            // The selected record data is set to the export’s dataSource property and passed along with the pdfExport method 
            let exportProperties = { 
                dataSource: selectedRecords, 
            }; 
            this.grid.pdfExport(exportProperties); 
        } else { 
            // If no records are selected, then the entire data is exported 
            this.grid.pdfExport(); 
        } 
    } else if (args.item.text === "Excel Export") { 
        // The same approach can be used for excel export 
    } 
} 
 
We have prepared a sample based on this for your reference. You can find it below, 
 
 
More details on this can be checked in the below documentation links, 
 
                               https://ej2.syncfusion.com/angular/documentation/grid/excel-exporting/#custom-data-source 
 
 
Let us know if you have any concerns. 
 
Regards, 
Sujith R 


Loader.
Up arrow icon