Search results

Exporting the Selected Records in ASP.NET Core Grid control

25 Oct 2021 / 1 minute to read

You can export the selected records data by passing it to exportProperties.dataSource Property in the toolbarClick event.

In the below exporting demo, We can get the selected records using getSelectedRecords method and pass the selected data to PdfExport or excelExport property.

Copied to clipboard
<ejs-grid id="Grid" dataSource="@ViewBag.DataSource" allowPdfExport="true" allowExcelExport="true" toolbarClick="toolbarClick" toolbar="@(new List<string>() {"PdfExport", "ExcelExport"})"
          allowPaging="true" allowFiltering="true">
    <e-grid-pagesettings pageCount="5" pageSize="5"></e-grid-pagesettings>
    <e-grid-selectionSettings type="Multiple"></e-grid-selectionSettings>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" width="150"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>

    function toolbarClick(args) {
        var gridObj = document.getElementById("Grid").ej2_instances[0];
        if ( === 'Grid_pdfexport') {
            var pdfdata = gridObj.getSelectedRecords();
            var exportProperties = {
                dataSource: pdfdata
        if ( === 'Grid_excelexport') {
            var exceldata = gridObj.getSelectedRecords();
            var exportProperties = {
                dataSource: exceldata
Copied to clipboard
public IActionResult Index()
    ViewBag.DataSource = OrderDetails.GetAllRecords();
    return View();