public ActionResult DataSource(DataManager dm)
{
BindDataSource();
IEnumerable DataSource = order.ToList();
DataResult result = new DataResult();
DataOperations operation = new DataOperations();
result.result = DataSource;
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
{
result.result = operation.PerformSorting(result.result, dm.Sorted);
}
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
result.result = operation.PerformWhereFilter(DataSource, dm.Where, dm.Where[0].Operator);
}
result.count = result.result.AsQueryable().Count();
if (dm.Skip > 0)
result.result = operation.PerformSkip(result.result, dm.Skip);
if (dm.Take > 0)
result.result = operation.PerformTake(result.result, dm.Take);
return Json(new { result = result.result, count = result.count }, JsonRequestBehavior.AllowGet);
}
|
Ugh. I'm kicking myself over that one. Your solution works perfectly. Thank you again for the wonderful support.
Hi,
I have my filtering working nice.
But my client has a refined taste for requesting complex things.
So I have this code working fine:
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
dm.Where.ForEach(f => f.Operator = "contains");
result.result = operation.PerformWhereFilter(result.result, dm.Where, "contains");// dm.Where[0].Operator);
result.count = result.result.Cast<QuoteLineMaterial>().Count();
}
But the client want to be able to filter by multiple words, like
they filter brands by "brand1+brand2" and the grid show the results for brand1 OR brand2
Can you help me with this request?
Thank you for your reply,
Probably I was not clear enought in my question and I am sorry for that.
The question is, in the filterbar of the grid, the customer wants to write "car+blue" and the grid automaticly filter that column to values wich have both words, like "Blue Car of Brand Y".
Meanwhile I grabed my big hammer and came out with this amazing solution :)
And It actualy works!
if (dm.Where != null && dm.Where.Count > 0) //Filtering
{
dm.Where.ForEach(f => f.Operator = "contains");
List<WhereFilter> filters = new List<WhereFilter>();
for (int i = 0; i < dm.Where.Count; i++)
{
if(dm.Where[i].value!=null && dm.Where[i].value.ToString().Contains("+"))
{
var items = dm.Where[i].value.ToString().Split('+');
foreach (var item in items) {
filters.Add(new WhereFilter() {
Condition = dm.Where[i].Condition,
Field = dm.Where[i].Field,
IgnoreCase = dm.Where[i].IgnoreCase,
IsComplex = dm.Where[i].IsComplex,
Operator = dm.Where[i].Operator,
predicates = dm.Where[i].predicates,
value = item
});
}
}
else
{
filters.Add(dm.Where[i]);
}
}
dm.Where = filters;
result.result = operation.PerformWhereFilter(result.result, dm.Where, "contains");
result.count = result.result.Cast<QuoteLineMaterial>().Count();
}