Grid Query Syntax

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".

  1. How do I chain "where" methods such that this will work?
  2. Where can I find *comprehensive* documentation on the query structure used?
Kind regards,
Judi Smith



5 Replies

PS Prathap Senthil Syncfusion Team May 27, 2024 06:25 AM UTC

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.

  • To analyze the reported issue, could you please share a simple and reproducible sample that demonstrates the problem? This will assist us in identifying the issue more efficiently and providing a resolution.
  • If possible, kindly share your attempt to replicate the issue using the attached simple sample.

Sample: https://blazorplayground.syncfusion.com/embed/BZBTDorcsFiONWvp?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

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

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Data.WhereFilter.html#Syncfusion_Blazor_Data_WhereFilter_And_Syncfusion_Blazor_Data_WhereFilter_

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Data.WhereFilter.html#Syncfusion_Blazor_Data_WhereFilter_Or_Syncfusion_Blazor_Data_WhereFilter_



Regards,
Prathap Senthil



JS Judi Smith May 27, 2024 03:24 PM UTC

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.



PS Prathap Senthil Syncfusion Team May 28, 2024 12:38 PM UTC

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:

  • Any error messages or issues you are encountering after the modification.
  • If possible, a simple reproducible sample or steps to reproduce the issue.

These details will help us understand the problem better and provide a more accurate solution.



JS Judi Smith May 29, 2024 02:28 AM UTC

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));
    }
}




PS Prathap Senthil Syncfusion Team May 30, 2024 05:06 AM UTC

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.


Loader.
Up arrow icon