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 do I apply a filter on a grid using javascript?

I am creating the following grid.


@(Html.EJ().Grid<MerchantsViewModel>("MerchantsGrid"


).Datasource((IEnumberable<object>)Model.Merchants)

.FilterSettings(filter => { filter.ShowFilterBarStatus().StatusBarWidth(500).FilterType(FilterType.Excel).FilterBarMode(FilterBarMode

.Immediate); })

.Columns(col =>

{

col.Field("Email").HeaderText("Email(s)").Width(120).Add();

.

.

.

And I want to filter (based on an event). How would I filter on my grid data to display only the data that has aas@as.com in the Email field? 

function applyFilter(filterValue) {

var stringValue = filterValue == "All" ? "" : filterValue;

var gridObj = $("#MerchantsGrid").ejGrid("instance");

var filteredActiveData = ej.DataManager(gridObj).executeLocal(ej.Query().where("Email", ej.FilterOperators.contains, "aas@as.com", false));

}
















































}



1 Reply

MS Madhu Sudhanan P Syncfusion Team February 24, 2015 12:39 PM UTC

Hi Christine,

Thanks for using Syncfusion products.

We have analyzed the provided code snippet and suspect that you have passed the grid object directly to the ej.DataManager (“ as ej.DataManager(gridObj).”) instead of passing the grid datasource and hence the data was not filtered correctly.

We can filter the Email field with value “aas@as.com” from grid datasource as follows.

function applyFilter(filterValue) {

var stringValue = filterValue == "All" ? "" : filterValue;

var gridObj = $("#MerchantsGrid").ejGrid("instance");

var filteredActiveData = ej.DataManager(gridObj.model.dataSource).executeLocal(ej.Query().where("Email", ej.FilterOperators.contains, "aas@as.com", false));

}

Now in the above highlighted section, you can see that we have passed the grid datasource to ej.DataManager and now filteredActiveData will contain the filtered value.

If you want to display the filtered value in grid, then we can do as follows.

gridObj.dataSource(filteredActiveData)

For more information on performing custom or external filtering in grid, please refer the below link (Refer the External filter section in the below link).

http://help.syncfusion.com/ug/js/default.htm#!documents/filtering1.htm

Please let us know if you have any queries.

Regards,

Madhu Sudhanan. P



Loader.
Live Chat Icon For mobile
Up arrow icon