- Home
- Forum
- ASP.NET MVC - EJ 2
- Server Side Filtering
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.
SIGN IN To post a reply.
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,
Sample : http://www.syncfusion.com/downloads/support/directtrac/general/ze/gridmvclocalization1198539651
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
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 : Using “FilterSettings.Columns” property
We can perform initial filtering by setting the predicates in the FilterSettings.Columns property of Grid. Please refer the documentation link below,
Documentation : https://ej2.syncfusion.com/16.1.37/aspnet/documentation/grid/filtering.html?syntax=razor#initial-filter
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.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
NI Nidhi
- May 9, 2018 12:09 PM UTC
- May 29, 2018 01:02 PM UTC