We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to retrieve records after filtering / grouping without paging?

Hello, I am setting up a grid with ExportExcel, filtering, grouping, paging and I would like to be able to retrieve the records that are the result after filtering and grouping but without being limited by the paging (that only one page comes out and not all pages).
Something similar to when you filter and / or group and export to excel

My code in view:
@(Html.EJS().Grid("Facturas")
        .DataSource(ds=>ds.Url(Url.Action("DS")).Adaptor("UrlAdaptor").CrossDomain(true))
        .AllowExcelExport()
        .ShowColumnMenu()
        .AllowPaging()
        .AllowFiltering()
        .AllowGrouping()
        .FilterSettings(f => f.Type(Syncfusion.EJ2.Grids.FilterType.Excel))
        .Columns(c =>
        {
            c.Field("EquipoId").AllowEditing(false).IsPrimaryKey(true).Add();
            c.Field("PrecioBase").Format("C2").Add();
            c.Field("IVA").AllowEditing(false).Format("C2").Add();
            c.Field("TotalCliente").AllowEditing(false).Format("C2").Add();
            c.Field("Total").AllowEditing(false).Format("C2").Add();
        })
        .PageSettings(p=>p.PageSize(5))
        .EditSettings(es =>
        {
            es.AllowEditing(true);
        })
        .Toolbar(new string[] { "Edit", "Update", "Cancel", "ExcelExport" }).ToolbarClick("tclic")
        .ActionComplete("Completo")
        .Render()
)

<script>
    function tclic(args) {
        console.log(args);
        if (args.item.id === 'Facturas_excelexport') {

            var excelExportProperties = {
                fileName: "RepEquipos_" + "@DateTime.Now" + ".xlsx"
            };
            var grid = document.getElementById("Facturas").ej2_instances[0];
            var data = grid.dataSource;
            console.log(data);
            grid.excelExport(excelExportProperties);
        }
        }
    function Completo(args) {
        console.log(args);
        if (args.requestType === "filtering") {
            console.log(args);
            window.ids = new Array();
            var rows = args.rows;
            for (var i = 0; i < rows.length; i++) {
                if (!("key" in rows[i].data)) {
                    window.ids.push(rows[i].data);
                }
            }
        }
        if (args.requestType==="grouping") {
            console.log(args);
            window.ids = new Array();
            var rows = args.rows;
            for (var i = 0; i < rows.length; i++) {
                if (!("key" in rows[i].data)) {
                    window.ids.push(rows[i].data);
                }
            }
        }
    }
    function d1() {
        var x = window.ids;
        console.log(x);
        }

    window.addEventListener('DOMContentLoaded', function () {
        window.ids = new Array();
        });
    function test(args) {
        console.log(args);
    }
</script>

Can I retrieve all records after filtering or grouping of all pages and not just the current one?

Attachment: FilterGroup_bc92b794.rar

3 Replies

PS Pavithra Subramaniyam Syncfusion Team October 17, 2019 11:17 AM UTC

Hi Juan, 
 
Greetings from Syncfusion. 
 
Query: ”How to retrieve records after filtering / grouping without paging ”. 
 
You can achieve your requirement by using generateQuery and executeQuery methods of EJ2 DataManager. Please refer to the below code blocks and sample link for more information. 
 
    @Html.EJS().Grid("Grid").DataSource(ds => ds.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor").InsertUrl("/Home/Insert").RemoveUrl("/Home/Remove") 
.UpdateUrl("/Home/Update")).Columns(col => 
{ 
    col.Field("OrderID").HeaderText("Order ID").Width("120").IsPrimaryKey(true).TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
. . . . 
}).Height("400").AllowExcelExport().AllowPaging().AllowFiltering(true).AllowGrouping().AllowSorting().FilterSettings(filter => { filter.Type(Syncfusion.EJ2.Grids.FilterType.Menu); }).ToolbarClick("toolbarClick").Toolbar(new List<string> 
        () { "ExcelExport" }).Render() 
</div> 
 
<script> 
     function toolbarClick(args) { 
        var gridObj = document.getElementById("Grid").ej2_instances[0]; 
         if (args.item.id === 'Grid_excelexport') { 
 
             var query = gridObj.renderModule.data.generateQuery(true); 
        // execute the action queries in getDataModule. 
             gridObj.getDataModule().executeQuery(query).then((e) => { 
                 console.log(e.result); // you can retrieve the all data after filter and grouping 
 
             }) 
            gridObj.excelExport(); 
        } 
     } 
</script> 
 
 
Screenshot : (After filtered with BLONP) 
 
 
 
 
Please get back to us if you need further assistance. 

Regards,
 
Pavithra S. 



JC Juan Cruz October 17, 2019 02:30 PM UTC

I already did the test with the code you provided me and it works correctly. I only have one question: How can I handle if an error occurs in:
gridObj.getDataModule().executeQuery(query).then((e) => {
            console.log(e.result); // you can retrieve the all data after filter and grouping 

        })
I really appreciate your help


PS Pavithra Subramaniyam Syncfusion Team October 18, 2019 06:50 AM UTC

Hi Juan, 
 
You can handle failure request by using the executeQuery catch method. Please find the below code example for more information. 
 
[index.cshtml] 
var query = gridObj.renderModule.data.generateQuery(true); 
                             // execute the action queries in getDataModule.. 
             new ej.data.DataManager({url:"gr"}).executeQuery(query).then((e) => { 
                 console.log(e.result); // you can retrive the all data after filter and grouping 
             }).catch((e) => { 
                 console.log(e.error); 
             }); 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon