|
<ejs-grid id="Grid"
dataSource="@ViewBag.DataSource"
allowSorting="true"
allowPaging="true"
allowExcelExport="true"
allowPdfExport="false"
allowFiltering="true"
contextMenuItems="@(new List<object>() { "AutoFit", "AutoFitAll", "SortAscending", "SortDescending","Copy", "Edit", "Delete", "FirstPage", "PrevPage","LastPage", "NextPage"})"
toolbar="@(new List<string>() {"Search", "Print", "ExcelExport" })" toolbarClick="toolbarClick"> // bind toolbarClick event
<e-grid-pagesettings pageCount="5"></e-grid-pagesettings>
<e-grid-filterSettings type="CheckBox"></e-grid-filterSettings>
<e-grid-columns>
<e-grid-column field="OrderID" headerText="OrderID" textAlign="Left" width="140"></e-grid-column>
<e-grid-column field="CustomerID" headerText="CustomerID" width="140"></e-grid-column>
<e-grid-column field="ShipName" headerText="ShipName" width="140"></e-grid-column>
<e-grid-column field="ShipCity" headerText="ShipCity" width="140"></e-grid-column>
</e-grid-columns>
</ejs-grid>
<script>
function toolbarClick(args) {
// get grid element instances
var gridObj = document.getElementById("Grid").ej2_instances[0];
if (args.item.id === 'Grid_excelexport') { // Excel Export button id = Grid element ID + “_“ + “excelexport”
// call excel export method to export the grid
gridObj.excelExport();
}
}
</script>
|
|
<script>
window.toolbarClick = function (args) {
var gridObj = document.getElementById("Grid").ej2_instances[0];
if (args.item.id === 'Grid_excelexport') {
gridObj.excelExport();
}
}
</script>
|
|
<ejs-grid id="Grid" dataSource="@ViewBag.dataSource"
allowPaging="true"
allowSorting="true"
allowResizing="true"
allowFiltering="true"
allowExcelExport="true"
allowGrouping="true"
toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel","Search" ,"ExcelExport"})"
toolbarClick="toolbarClick">
-------
</ejs-grid> |
Hi Scot,
Greetings from syncfusion support.
Query : I have a data grid with a toolbar that contains the Export to Excel button. When I click on that button, nothing happens.
We have analyzed your query and understood that you need export the grid when clicking the Excel Export button in the toolbar. You can achieve your requirement by using toolbarClick event and calling excelExport() method, please refer the below code example and sample for more information.
<ejs-grid id="Grid"dataSource="@ViewBag.DataSource"allowSorting="true"allowPaging="true"allowExcelExport="true"allowPdfExport="false"allowFiltering="true"contextMenuItems="@(new List<object>() { "AutoFit", "AutoFitAll", "SortAscending", "SortDescending","Copy", "Edit", "Delete", "FirstPage", "PrevPage","LastPage", "NextPage"})"toolbar="@(new List<string>() {"Search", "Print", "ExcelExport" })" toolbarClick="toolbarClick"> // bind toolbarClick event<e-grid-pagesettings pageCount="5">e-grid-pagesettings><e-grid-filterSettings type="CheckBox">e-grid-filterSettings><e-grid-columns><e-grid-column field="OrderID" headerText="OrderID" textAlign="Left" width="140">e-grid-column><e-grid-column field="CustomerID" headerText="CustomerID" width="140">e-grid-column><e-grid-column field="ShipName" headerText="ShipName" width="140">e-grid-column><e-grid-column field="ShipCity" headerText="ShipCity" width="140">e-grid-column>e-grid-columns>ejs-grid><script>function toolbarClick(args) {// get grid element instancesvar gridObj = document.getElementById("Grid").ej2_instances[0];if (args.item.id === 'Grid_excelexport') { // Excel Export button id = Grid element ID + “_“ + “excelexport”// call excel export method to export the gridgridObj.excelExport();}}script>
I wrote a dissertation related to this issue and the service https://writix.co.uk/write-my-dissertation-for-me helped me a lot, with which I have been collaborating for several months. I really like the quality and price of the services provided.
Refer excel export documentation for more information.
Please get back to us if you need further assistance on this.
Regards,Rajapandiyan S
Thank you for such a useful information!