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

Grid Filtered Data Source

Hi

I am looking for a way to get the data of a grid after filtering has been applied, how can this be achieved?

Regards

1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team March 4, 2019 11:52 AM UTC

Hi Rikard, 

Greetings from Syncfusion. 

Based on your query we suspect that you want to get the filtered record from. So, we suggest you to use the below code example.    

In the below code example we have get the filtered record by clicking the external button. 

[index.html] 

<ejs-button id="clickbutton" content="getFilteredData"></ejs-button> 
 
<ejs-grid id="Grid" dataSource="ViewBag.dataSource" allowPaging="true" allowFiltering="true"> 
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings> 
    <e-grid-columns> 
        <e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column> 
        <e-grid-column field="CustomerID" headerText="Customer ID" width="100"></e-grid-column> 
        <e-grid-column field="EmployeeID" headerText="Employee ID" width="100"></e-grid-column> 
        <e-grid-column field="Freight" width="100"></e-grid-column> 
        <e-grid-column field="Verified" headerText="Verified" width="100"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 
 
 
<script> 
    document.getElementById('clickbutton').addEventListener('click', function (e) { 
        var f_data; 
        var grid = document.getElementById('Grid').ej2_instances[0]; 
        var query = grid.renderModule.data.generateQuery(); // get grid corresponding query  
        for (var i = 0; i < query.queries.length; i++) { 
            if (query.queries[i].fn == 'onPage') { 
                query.queries.splice(i, 1);       // remove page query to get all records  
                break; 
            } 
        } 
        var dm = new ej.data.DataManager(grid.dataSource) 
        f_data = dm.executeLocal(query); 
        alert(f_data.length); 
        }  
    ); 
</script> 



Please let us know if you need further assistance on this. 

Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon