Server Side Filtering

I have a grid which has huge number of records. I have implemented server side paging using skip and take like this:

Data = learningEntities.Employees.Join(learningEntities.EmployeeAddressDetails,
                        o => o.Id, od => od.EmployeeId,
                        (o, od) => new
                        {
                            Id = o.Id,
                            FirstName = o.FirstName,
                            LastName = o.LastName,
                            EmployeeNumber = o.EmployeeNumber,
                            DateOfJoining = o.DateOfJoining,
                            City = od.City,
                            State = od.State,
                            Pin = od.Pin
                        }).ToList().Skip(dm.Skip).Take(dm.Take);

Now, I need to implement server side filtering before applying the paging. Kindly provide a solution to achieve this. 

3 Replies

RS Renjith Singh Rajendran Syncfusion Team May 10, 2018 02:12 PM UTC

Hi Nidhi, 

Thanks for contacting Syncfusion support. 

We have analyzed your query. Based on your request we have prepared a sample with server side filtering in ASP.NET MVC using UrlAdaptor. Please download the sample from the link below, 

We have handled the filtering at server side with the codes below, 

[Client side codes] 
 
@Html.EJS().Grid("Grid").DataSource(dataManager => { dataManager.Url("/Home/UrlDatasource").Adaptor("UrlAdaptor"); }) 
.AllowFiltering(true).AllowPaging(true).Width("auto") 
.Columns(col => 
{ 
    ... 
}).Render() 
 
[Server side codes] 
 
public ActionResult UrlDatasource(Data dm) 
        { 
            var order = OrdersDetails.GetAllRecords(); 
            var Data = order.ToList(); 
            int count = order.Count(); 
            if (dm.where != null && dm.where.Count > 0 && dm.where[0].predicates != null) 
            { 
                //Codes to Perform Filtering 
                for (var i = 0; i < dm.where[0].predicates.Count; i++) 
                { 
                    switch (dm.where[0].predicates[i].field) 
                    { 
                        case "OrderID": 
                            Data = (from cust in Data 
                                    where cust.OrderID.ToString() == dm.@where[0].predicates[i].value 
                                    select cust).ToList(); 
                            break; 
                        ... 
                   } 
                    count = Data.Count; 
                } 
            } 
            return dm.requiresCounts ? Json(new { result = Data.Skip(dm.skip).Take(dm.take), count = count }) : Json(Data); 
        } 
        public class Data 
        { 
            ... 
            public List<Wheres> where { get; set; } 
        } 
public class Wheres 
{ 
    public List<Predicates> predicates { get; set; } 
    ... 
} 
public class Predicates 
{ 
    ... 
} 


Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran.                



NI Nidhi May 28, 2018 12:58 PM UTC

Hi Renjith,

Thanks for the solution. But here in the below lines we are making a call to the database to fetch entire set of records. Do we have any option to fetch the filtered records while querying the data.
var order = OrdersDetails.GetAllRecords(); 
var Data = order.ToList();




RS Renjith Singh Rajendran Syncfusion Team May 29, 2018 01:02 PM UTC

Hi Pawan, 

We have analyzed your query. We suspect that you would like to display the filtered values at initial loading of Grid. We suggest you the following two possible solutions to achieve your requirement. 

Solution 1 : UsingFilterSettings.Columns” property 
We can perform initial filtering by setting the predicates in the FilterSettings.Columns property of Grid. Please refer the documentation link below, 
 
Please refer the code example below, 
    @{ 
        List<object> filterColumns = new List<object>(); 
        filterColumns.Add(new { field = "CustomerID", matchCase = false, @operator = "equal", predicate = "and", value = "ALFKI" }); 
    } 
    @Html.EJS().Grid("Grid") 
        .Columns(col => 
        { 
            ... 
       }).FilterSettings(f => f.Columns(filterColumns)).Render() 
 
Solution 2 : By using the “Query” property of Grid 
Pass the query to the server side. Based on the query, the data will be filtered and displayed in Grid. Please refer the code example below, 

//Here we have filtered value based on CustomerID column 
 
@Html.EJS().Grid("Grid").DataSource(...).Query("new ej.data.Query().where('CustomerID','equal', 'ALFKI')").AllowFiltering(true) 
.Columns(col => 
{ 
    ... 
}).Render() 


Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


Loader.
Up arrow icon