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.
Unfortunately, activation email could not send to your email. Please try again.

Filter Grid from js

Thread ID:

Created:

Updated:

Platform:

Replies:

121437 Dec 15,2015 04:10 AM Dec 17,2015 01:57 AM ASP.NET MVC 4
loading
Tags: Grid
RA
Asked On December 15, 2015 04:10 AM

Hi all
I am using EJ().Grid() and trying to filter it from js like this:

var grid = $("#MyGrid").data("ejGrid");
grid.filterColumn("Age", "greaterthanorequal", 15);

However, I need to filter it by more than one column, in one ajax request.

can anybody help with this please ?

RA
Replied On December 15, 2015 04:20 AM

I am trying to filter the grid by a DateTime property, and to apply a "between" operator.
I saw that this is not supported by default operators, so I tried to use "lessthanorequal" and "greaterthanorequal".
But for this to work, I need to apply both filters in one ajax call, and this is what I am trying to figure out.

Balaji Marimuthu [Syncfusion]
Replied On December 16, 2015 03:42 AM

Hi Rami,

Thanks for contacting Syncfusion support.

To achieve your requirement we suggest you to push the filter values to the filteredColumns property in filterSettings and call the refreshContent method to refresh the grid content in order to display the filtered records. Refer to the code example and sample as below.
Sample: Filtercolumn


<input id="btn" type="button" value="filter" onclick="btnclick()" />


@(Html.EJ().Grid<MvcApplication1.OrdersView>("FlatGrid")

        .Datasource((IEnumerable<object>)ViewBag.datasource)

         .AllowPaging()    /*Paging Enabled*/

         .AllowFiltering()

        .Columns(col =>

        {

            col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add();

            col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add();

            col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add();

            col.Field("OrderDate").HeaderText("Order Date").TextAlign(TextAlign.Right).Width(80).Format("{0:MM/dd/yyyy hh:mm:ss}").Add();

        })

        )


<script type="text/javascript">


    function btnclick() {

        var obj = $("#FlatGrid").ejGrid("instance");

        obj.model.filterSettings.filteredColumns.push({ field: "OrderDate", operator: "lessthanorequal", value: new Date("11/11/1997"), matchcase: false, predicate: "and" });

        obj.model.filterSettings.filteredColumns.push({ field: "OrderDate", operator: "greaterthanorequal", value: new Date("05/06/1997"), matchcase: false, predicate: "and" });


        obj.refreshContent();//refresh the grid content

    }

   
</script>



In above code example, we have filtered the columns in button click. Refer to the Document for more information in following link.
http://help.syncfusion.com/js/api/ejgrid#methods:refreshcontent
http://help.syncfusion.com/js/api/ejgrid#members:filtersettings-filteredcolumns


Query: However, I need to filter it by more than one column, in one ajax request.
Are you want to perform the filtering operation in server side/ AJAX success? Please

Please let us know if you have any concerns.


Regards,
Balaji Marimuthu

RA
Replied On December 16, 2015 03:48 AM

I was doing the same thing, but forgot to set predicate = "and"

Thanks a lot

Balaji Marimuthu [Syncfusion]
Replied On December 17, 2015 01:57 AM

Hi Rami,

Thanks for the update.

We are happy that the provided solution helped you. Please get back to us if you need any further assistance. We will be happy to assist you.

Regards,
Balaji Marimuthu

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;