public ActionResult DataSource(DataManager dm) { //SIMPLY RETURNING take AND skip values, not handled other grid actions dataresult.result = mylist.Skip(dm.skip).Take(dm.take); dataresult.count = mylist.Count();
return Json(dataResult, JsonRequestBehavior.AllowGet); |
private ICriteria ToQuery(DataManager dm, ISession session) {
ICriteria criteria = session.CreateCriteria<EmployeeMap>(); Count = session.CreateCriteria<EmployeeMap>().List().Count; Order order = null; if (dm.Where != null && dm.Where.Count > 0) //Filtering { for (var i = 0; i < dm.Where.Count; i++) {
WhereFilter filter = dm.Where[i]; if (filter.IsComplex) WhereFilter(criteria, filter); //Handle multiple column filter – REFER BELOW SAMPLE FOR CODE if (filter.Operator == "equal") criteria.Add(Restrictions.Eq(filter.Field, filter.value)); if (filter.Operator == "notequal") criteria.Add(Restrictions.Not(Restrictions.Eq(filter.Field, filter.value))); if (filter.Operator == "greaterthan") criteria.Add(Restrictions.Ge(filter.Field, filter.value)); if (filter.Operator == "lessthan") criteria.Add(Restrictions.Lt(filter.Field, filter.value)); if (filter.Operator == "greaterthanorequal") criteria.Add(Restrictions.Ge(filter.Field, filter.value)); if (filter.Operator == "lessthanorequal") criteria.Add(Restrictions.Le(filter.Field, filter.value)); if (filter.Operator == "startswith") criteria.Add(Restrictions.Like(filter.Field, filter.value + "%")); if (filter.Operator == "endswith") criteria.Add(Restrictions.Like(filter.Field, "%" + filter.value)); if (filter.Operator == "contains") criteria.Add(Restrictions.Like(filter.Field, filter.value.ToString(), MatchMode.Anywhere)); Count = criteria.List().Count; //Required to show filter count } } if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting { for (var i = 0; i < dm.Sorted.Count; i++) { order = dm.Sorted[i].Direction == "ascending" ? Order.Asc(dm.Sorted[i].Name) : Order.Desc(dm.Sorted[i].Name); criteria.AddOrder(order); } } if (dm.Skip != 0) //Paging { criteria.SetFirstResult(dm.Skip); } if (dm.Take != 0) //Paging { criteria.SetMaxResults(dm.Take); } return criteria; |
//PROVIDE GRID DATASOURCE public ActionResult GetData(DataManager dm) { using (ISession session = AppSession.OpenSession()) { list = ToQuery(dm,session).List<EmployeeMap>(); } return Json(new { result = list, count = Count }, JsonRequestBehavior.AllowGet); |
Good day
I am new to blazor and syncfusion,
I can use your ToQuery method code and it will work very well I think, however where does ICriteria come from?
I have an Interface ISession as I'm using the WebApiAdaptor but I don't have an interface called ICriteria.
I am using Visual Studio 2022.
Please help as I would like to use your code.
Hi Jessica,
Before we start proceeding with your query, we request you to share with us the details below to provide you with the solution as early as possible.
Regards,
Pon selva