I have the following odata4 query strings:
https://localhost:7279/odata/properties?filter=Projects/all(a:a/ProjectId ne 3)
https://localhost:7279/odata/properties?filter=Projects/any(a:a/ProjectId eq 3)
I want to populate dropdown lists using the results of these queries.
How do I model these filters using the Query class?
The classes are:
public class Property
{
public int PropertyId { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Property name is required")]
public string Name { get; set; }
public int ClientId { get; set; }
public Client Client { get; set; }
public ICollection<Project> Projects { get; set; }
}
public class Project
{
public int ProjectId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int ClientId { get; set; }
public Client Client { get; set; }
public ICollection<Property> Properties { get; set; }
}
Hi Carl,
Greetings from Syncfusion support.
You can bind the OdataV4 service in the dropdownlist similar to the below code.
|
@using System.ComponentModel.DataAnnotations @using Syncfusion.Blazor.Data @using Syncfusion.Blazor.DropDowns
<SfDropDownList TValue="string"TItem="Property" Placeholder="Select a customer" Query="@Query"> <SfDataManager Url=https://localhost:7279/odata/properties Adaptor="Syncfusion.Blazor.Adaptors.ODataV4Adaptor" CrossDomain=true></SfDataManager> <DropDownListFieldSettings Text="Name" Value="ClientId"></DropDownListFieldSettings> </SfDropDownList>
@code { public Query Query = new Query().Select(new List<string> { "Projects" }).RequiresCount();
public class Property
{
public int PropertyId { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Property name is required")]
public string Name { get; set; }
public int ClientId { get; set; }
public Client Client { get; set; }
public ICollection<Project> Projects { get; set; }
}
public class Project
{
public int ProjectId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int ClientId { get; set; }
public Client Client { get; set; }
public ICollection<Property> Properties { get; set; }
}
public class Client { public string ClientValue { get; set; } } } |
Refer to the documentation below for further reference
https://blazor.syncfusion.com/documentation/dropdown-list/data-source#binding-remote-data
Refer to below documentation for complex class binding
https://blazor.syncfusion.com/documentation/dropdown-list/data-source#array-of-complex-data
Regards,
Naveen Palanivel.
Thank you for your reply. I know how to use the Query in the grid what I can't figure out is how to setup the query based on the complex filters required. They are:
https://localhost:7279/odata/properties?filter=Projects/all(a:a/ProjectId ne 3)
https://localhost:7279/odata/properties?filter=Projects/any(a:a/ProjectId eq 3)
Hi Carl,
Sorry for the Inconvenience.
We are currently Validating the reported query at our end and we will update the further details within two business days(June 10, 2022). Until then we appreciate your patience.
Regards,
Naveen Palanivel.
Hi Carl,
Thanks for the patience.
Query: “I know how to use the Query in the grid what I can't figure out is how to setup the query based on the complex filters required. ”
Kindly refer to the below code example to filter the complex column in Grid using the Query property. Complex property needs to be Expanded from ODataV4 service to bind data properly.
|
<SfGrid TValue="Organization" Query="@RemoteDataQueryGrid" AllowFiltering="true" AllowPaging="true"> <SfDataManager Url=http://localhost:7112/odata/Organizations Adaptor="Adaptors.ODataV4Adaptor" CrossDomain=false></SfDataManager> <GridColumns> <GridColumn Field="Party.ExternalId" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> <GridColumn Field=@nameof(Organization.OrganizationName) HeaderText="Customer Name" Width="150"></GridColumn> <GridColumn Field=@nameof(Organization.OrganizationName2) HeaderText=" Order Date" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> <GridColumn Field="Party.PartyNumber" HeaderText="Freight" TextAlign="TextAlign.Right" Width="120"></GridColumn> </GridColumns> </SfGrid>
@code{ public Query RemoteDataQueryGrid = new Query().Expand(new List<string> { "Party" });
SfComboBox<string, Organization> comboObj { get; set; } public List<Organization> Organizations { get; set; } = new List<Organization>();
public void Clicked() { RemoteDataQueryGrid = new Query().Expand(new List<string> { "Party" }).Where(new WhereFilter() { Field = "Party/PartyNumber",Operator = "startswith", value = "14000"}).Take(6).RequiresCount();
} |
Kindly get back to us if you have further queries.
Regards,
Vignesh Natarajan