<div class="control-section">
<button id="store" class="e-btn e-primary" onclick="exportAllData()">Export All Data</button>
@Html.EJS().Grid("Grid").AllowExcelExport().DataSource(ds => ds.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor")).ToolbarClick("toolbarClick").Columns(col =>
{
. . .
}).Height("400").AllowPaging().Toolbar(new List<string>
() { "ExcelExport" }).AllowFiltering().FilterSettings(filter => filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu)).Render()
</div>
<script>
function toolbarClick(args) {
var gridObj = document.getElementById("Grid").ej2_instances[0];
if (args.item.text === 'Excel Export') {
gridObj.excelExport();
}
}
function exportAllData() {
var gridObj = document.getElementById("Grid").ej2_instances[0];
gridObj.getDataModule().executeQuery(new ej.data.Query()).then(e => {
gridObj.excelExport({ dataSource: e.result });
})
}
</script> |
@(Html.EJ().Button("Excel").Text("Excel").ClientSideEvents(evt => evt.Click("exportGrid")))
@(Html.EJ().Grid<object>("Grid")
.Datasource(datasource => datasource.URL(@Url.Action("DataSource"))
.Adaptor(AdaptorType.UrlAdaptor))
.AllowPaging().AllowFiltering()
.Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Add();
col.Field("CustomerID").HeaderText("Customer ID").Add();
col.Field("EmployeeID").Add();
col.Field("Freight").Add();
})
)
<script>
function exportGrid(args) {
var gridObj = $("#Grid").ejGrid("instance"); //grid instance. here "Grid" is grid's ID
gridObj.addIgnoreOnExport("filterSettings");
// adding filterSettings to ignoreOnExport so that complete grid data will be exported instead of filtered data
var action = args.model.text + "Export";
gridObj.export("/Grid/ExportToExcel/" + action);
}
</script>
|