Hi Friends,
As we have verified in the below URL for the remote paging and filtering operation, we have found that for the string and integer column filtering the column name shall be hard coded in the "private IQueryable ApplyFilterExpr(NameValueCollection queryString, IQueryable data) " function for the equals and doesnotequalsto filtering condition.
https://www.igniteui.com/help/handling-remote-features-manually#filtering
Since we are using more number of grid pages and we could not able to hard code all the column names to apply the filter. is there any possibilities to get the column data type so that we will use the same in the above function to apply the filtering.
The code available in the above URL, has been copy below.
private IQueryable ApplyFilterExpr(NameValueCollection queryString, IQueryable data){ List exprs = GetFilterExpressions(queryString); StringBuilder builder = new StringBuilder(); int count = 0;
for (int i = 0; i < exprs.Count; i++) { if (count != 0 && count <= exprs="" count="" -="" 1="" br=""> { builder.Append(exprs[i].Logic.ToLower() == "AND".ToLower() ? " AND " : " OR "); } count++;
string condition = exprs[i].Condition; string expr = exprs[i].Expr; string colKey = exprs[i].Key; var dt = DateTime.Now;
switch (condition.ToLower()) { case "startswith": builder.Append(colKey + ".StartsWith(\"" + expr + "\")"); break; case "contains": builder.Append(colKey + ".Contains(\"" + expr + "\")"); break; case "endswith": builder.Append(colKey + ".EndsWith(\"" + expr + "\")"); break;
case "equals": if (colKey == "ShipName") { //col type is string builder.Append(colKey + " == \"" + expr + "\""); } else { //col type is number builder.Append(colKey + " == " + expr); }
break; case "doesnotequal": if (colKey == "ShipName") { //col type is string builder.Append(colKey + " != \"" + expr + "\""); } else { //col type is number builder.Append(colKey + " != " + expr); } break;
case "doesnotcontain":
builder.Append("! " + colKey + ".Contains(\"" + expr + "\")"); break; case "lessthan": builder.Append(colKey + " < " + expr); break; case "greaterthan": builder.Append(colKey + " > " + expr); break; case "lessthanorequalto": builder.Append(colKey + " <= " + expr); break; case "greaterthanorequalto": builder.Append(colKey + " >= " + expr); break; case "on": dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(double.Parse(expr)).ToUniversalTime(); builder.Append("(" + colKey + ".Value.Day == " + dt.Day + " AND " + colKey + ".Value.Year == " + dt.Year + " AND " +colKey + ".Value.Month == " + dt.Month + ")"); break; case "noton": dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(double.Parse(expr)).ToUniversalTime(); builder.Append("!("+colKey + ".Value.Day == " + dt.Day + " AND " + colKey + ".Value.Year == " + dt.Year + " AND " + colKey + ".Value.Month == " + dt.Month + ")"); break; case "after": dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(double.Parse(expr)).ToUniversalTime(); builder.Append("((" + colKey + ".Value.Year > " + dt.Year + " OR (" + colKey + ".Value.Month > " + dt.Month + " AND " + colKey + ".Value.Year == " + dt.Year + ") OR (" + colKey + ".Value.Day > " + dt.Day + " AND " + colKey + ".Value.Year == " + dt.Year + " AND " + colKey + ".Value.Month == " + dt.Month + ")))"); break; case "before": dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(double.Parse(expr)).ToUniversalTime(); builder.Append("((" + colKey + ".Value.Year < " + dt.Year + " OR (" + colKey + ".Value.Month < " + dt.Month + " AND " + colKey + ".Value.Year == " + dt.Year + ") OR (" + colKey + ".Value.Day < " + dt.Day + " AND " + colKey + ".Value.Year == " + dt.Year + " AND " + colKey + ".Value.Month == " + dt.Month + ")))"); break; case "today": builder.Append("(" + colKey + ".Value.Day == " + DateTime.Now.Day + " AND " + colKey + ".Value.Year == " + DateTime.Now.Year + " AND " + colKey + ".Value.Month == " + DateTime.Now.Month + ")"); break; case "yesterday": DateTime yesterday = DateTime.Now.AddDays(-1); builder.Append("(" + colKey + ".Value.Day == " + yesterday.Day + " AND " + colKey + ".Value.Year == " + yesterday.Year + " AND " + colKey + ".Value.Month == " + yesterday.Month + ")"); break; case "thismonth": builder.Append("(" + colKey + ".Value.Year == " + DateTime.Now.Year + " AND " + colKey + ".Value.Month == " + DateTime.Now.Month + ")"); break; case "lastmonth": builder.Append("(" + colKey + ".Value.Year == " + (DateTime.Now.Year - 1) + " AND " + colKey + ".Value.Month == " + (DateTime.Now.Month - 1) + ")"); break; case "nextmonth": builder.Append("(" + colKey + ".Value.Year == " + (DateTime.Now.Year - 1) + " AND " + colKey + ".Value.Month == " + (DateTime.Now.Month + 1) + ")"); break; case "thisyear": builder.Append(colKey + ".Value.Year == " + DateTime.Now.Year); break; case "lastyear": builder.Append(colKey + ".Value.Year == " + (DateTime.Now.Year - 1)); break; case "nextyear": builder.Append(colKey + ".Value.Year == " + (DateTime.Now.Year + 1)); break; default: break; } } if (builder.Length > 0) { data = data.Where(builder.ToString(), new object[0]); }
return data;}
Hello Satkhi,
Another way to use remote features out of the box without need of implementing any custom logic is by setting DataSourceUrl option to the grid and passing it the action method on the server, which will return the data casted to the respective ICollection (IEnumerable, IQueryable). Please note also that this data action method should be decorated with "DataSourceAction" attribute in order the grid to know how to handle its remote operations.
Attached is a sample with similar scenario for your reference.
Regards,
Tsanna
As we have seen the provided sample application, the filtering operation is working as per the requirement but we have seen the paging was configured as local instead of remote. as per the client requirement, no data should be hold in the client side. please suggest is it possible to make it work by configuring the remote paging. since as we have configured the remote paging, the paging was not works properly.
GridSorting sorting = new GridSorting() { Type = OpType.Local, Mode = SortingMode.Single };GridPaging paging = new GridPaging() { Type = OpType.Local, PageSize = 10 };
also, we already implemented the application by writing the code in the client side and now we required the help by configuring the paging and filtering as remote in the client side. since the changes are implemented in many of the pages and if we required to change all the code to server side. it takes more time consuming to identify meet the release in time.
Could you please provide the support to work filtering on the above method we have requested.
Hello SATKHI,
Instead of handling the remote filtering manually on the server by checking all available columns in the grid and applying the respective filtering condition on them, I suggest you to create the grid entirely through the GridModel and set the Filtering type to "remote" and the grid will handle the filtering by itself. Here is a link to our documentation how to create grid in MVC using the GridModel class for your reference: https://www.igniteui.com/help/iggrid-developing-asp-net-mvc-applications-with-iggrid#syntax-grid-model
Attached is also a sample demonstrating remote filtering.
If you have further questions, please let me know.