I have a master grid and a detail grid for each row of the master grid. I populate the detail grid with a query (the first one below) for all the ranks associated with the program. The detail grid uses its own SfDataManager to retrieve records from the Ranks table.
I am struggling with the syntax for the grid query. This works:
public Query GetRanksQuery(Programs program)
{
return new Query()
.Where("ProgramId", "equal", program.Id)
}
Now I need to also filter on a field "IsArchived" The documentation states in many places that the Where method can be chained. So I tried:
public Query GetRanksQuery(Programs program)
{
return new Query()
.Where("ProgramId", "equal", program.Id)
.Where("IsArchived", "equal", "false");
}
I have also tried
publicQueryGetRanksQuery(Programs program)
{
returnnewQuery()
.Where("ProgramId","equal", program.Id)
.Where("IsArchived","equal",false);//without quotes
}
I also tried
publicQueryGetRanksQuery(Programs program)
{
returnnewQuery()
.Where("ProgramId","equal", program.Id)
.Where("RankName","notequal","Test");
}
In all cases, it appears that only the first where method is applied. Five records are returned with all the Queries, including the one with RankName = Test. There should be 4 records returned as there is only one that has IsArchived set to true (and also has a RankName of "Test")
Then I tried,
var rankFilter = new WhereFilter();
List<WhereFilter> predicate = new List<WhereFilter>();
predicate.Add(new WhereFilter(){ Field = "ProgramId", Operator = "equal", value = program.Id, IgnoreCase = true });
predicate.Add(new WhereFilter(){ Field = "IsArchived", Operator = "equal", value = false, IgnoreCase = true });
rankFilter = WhereFilter.And(predicate);
Query rankQuery = new Query().Where(rankFilter);
return rankQuery;
The above also does not work. No records are returned. I've also tried various representations of false. I also tried putting 2 for the value of program.Id.
A similar WhereFIlter created with predicates works in a different situation that is not a grid of any kind.
Nothing works other than the first simple "where".
Hi Judi,
We are unable to reproduce the reported issue when attempting to reproduce the
issue in the latest version 25.2.5 . For your reference we have attached
screen shot and simple sample .So, to
further proceed with the reporting
problem, we require some additional clarification from your end. Please share
the below details to proceed further at our end.
Above-requested details will be very helpful in validating
the reported query at our end and providing a solution as early as possible.
Thanks for your understanding.
Reference:
https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Data.Query.html
https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.PredicateModel.html
https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Data.WhereFilter.html
Regards,
Prathap Senthil
Thank you for your reply. As it turns out, the API controller is not an OData controller, so I had to modify the filter handling in the controller.
We understand that you had to modify the filter handling in your API controller since it is not an OData controller. To assist you better, could you please provide more details on the changes you made? Specifically, sharing the relevant parts of your modified controller code would be helpful. To proceed further, please share the following:
These details will help us understand the problem better and provide a more accurate solution.
Hi Prathap,
I have the following in the Get Method of the HTTP Controller. This allows grid filtering and sorting to work. I had to account for IsArchived in the Query.
var objList = objTask.AsQueryable();
var queryString = Request.Query;
string sort = queryString["$orderby"];
string filter = queryString["$filter"];
//Allows grid to send query parameter for hierarchical grid
//Grid sends the query as part of "$filter" as ProgramId eq {ProgramId#} eg ProgramId eq 2
if (filter != null)
{
if (filter.Contains("ProgramId") && !filter.Contains("IsArchived")) //Filter for all ProgramId regardless of IsArchived. //Filter on ProgramId
{
string[] words = filter.Split(' ');
var key = words[2];
objList = objList.Where(r => r.ProgramId.ToString().Contains(key));
}
else if (filter.Contains("ProgramId") && filter.Contains("IsArchived")) //Filter for ProgramId and IsArchived //Filter on IsArchived and ProgramId
{
var phrase = filter.Replace("(", "").Replace(")", "");
string[] words = phrase.Split(' ');
var id = words[2];
var archived = words[6];
objList = objList.Where(r => r.ProgramId.ToString().Contains(id) && r.IsArchived == bool.Parse(archived));
}
else //Filter based on RankName
{
var key = filter.Split(new string[] { "'" }, StringSplitOptions.None)[1].ToUpper();
objList = objList.Where(p => p.RankName.ToString().ToUpper().Contains(key));
}
}
if (sort != null)
{
if (sort.EndsWith(" desc"))
{
objList = objList.OrderByDescending(s => s.GetType().GetProperty(sort.Replace(" desc", "")).GetValue(s));
}
else
{
objList = objList.OrderBy(s => s.GetType().GetProperty(sort).GetValue(s));
}
}
Thanks for
the update,
Based on the code snippet you shared, it seems that the reported issue has been resolved on your end. We are now closing the thread.