Search also for Value in MultiSelectFieldSettings with WhereFilter

Hello,

i want to filter the grid using a column filter template with <SfMultiSelect />, for that i use a wherefilter, but i can not search for the Value, in this context: Id, only Text it used for it.

The column data(text) is different from the checkbox menu, with the new system we are doing we renamed some fields, but they might stay the same in the database...

How can i search for different/multiple fields instead of only one?
One StatusModel in the database is still called "Angebot", but in the dropdown its called "Angebot (versendet)", which will of course not match at all, but "Neu" & "in Bearbeitung" do work together.

My idea was to search for the Id, in this case the Value, not the Text of <MultiSelectFieldSettings Name="" Value=""/>

So, searching for Id would be much easier instead of Name which is not always matched with the one in the database. Any Suggestions?

Thank you in advance

// external cs file
public class StatusModel
{
public int Id { get; set; }
public string Name { get; set; }
}

public static List<StatusModel> Statuses = new List<StatusModel>() {
new StatusModel(){ Id = 1, Name = "Neu" },
new StatusModel(){ Id = 2, Name = "Angebot (versendet)" },
new StatusModel(){ Id = 3, Name = "in Bearbeitung" },
new StatusModel(){ Id = 4, Name = "Abschluss (Vertrag)" },
new StatusModel(){ Id = 5, Name = "Bestelleintritt" },
new StatusModel(){ Id = 6, Name = "Suchen ?!" },
new StatusModel(){ Id = 7, Name = "Abgelehnt" },
new StatusModel(){ Id = 8, Name = "Geprüftes Angebot (versendet)" },
new StatusModel(){ Id = 9, Name = "Wiedervorlage ?!" },
new StatusModel(){ Id = 10, Name = "Rückfragen" },
new StatusModel(){ Id = 11, Name = "In Prüfung" },
new StatusModel(){ Id = 12, Name = "Leasingunterlagen (versendet)" },
new StatusModel(){ Id = 13, Name = "Leasingunderlagen (Rücklauf)" },
new StatusModel(){ Id = 14, Name = "Zahlung" },
new StatusModel(){ Id = 15, Name = "Abgelehnt (privat)" },
new StatusModel(){ Id = 16, Name = "Abgelehnt (sonstige)" },
};


public static List<StatusModel> GetDefaultStatus(){
return new List<StatusModel>(){
Statuses[0]
};
}

// razor file

//TODO: get it working with custom text ("Angebot versendet" != "Angebot")
public void SetStatusFilter()
{
Query newQuery = new Query();
List<WhereFilter> Filters = new List<WhereFilter>();
WhereFilter ColPredicates;
foreach(var selectedStatus in EasyTable.SelectedStatus)
{
WhereFilter StatusFilter = new WhereFilter(){
Field = "Status",
// value = "Neu", // works
value = selectedStatus.Id, // or .Name, which works
Operator = "equals",
IgnoreCase = true
};
Filters.Add(StatusFilter);
JS.InvokeVoidAsync("console.log", selectedStatus.Id.ToString());
}
ColPredicates = WhereFilter.Or(Filters);
GridQuery = newQuery.Where(ColPredicates);
}

// and

<GridColumn Field="Status"
HeaderText="Status"
MinWidth="50"
Width="75"
MaxWidth="300"
TextAlign="TextAlign.Left">
<FilterTemplate>
<SfMultiSelect
@bind-Value=EasyTable.SelectedStatus
TValue="@(List<EasyTable.StatusModel>)"
TItem=EasyTable.StatusModel
AllowFiltering=false
Placeholder=""
Mode=VisualMode.CheckBox
DataSource=EasyTable.Statuses
FilterBarPlaceholder=""
PopupHeight="600px"
PopupWidth="350px"
>

<MultiSelectEvents
TItem="EasyTable.StatusModel"
TValue="List<EasyTable.StatusModel>"
OnClose="() => SetStatusFilter()"
/>
@* only Name is searched, not Id *@
<MultiSelectFieldSettings
Text="Name"
Value="Id"
/>

</SfMultiSelect>
</FilterTemplate>
</GridColumn>


Attachment: Bildschirmfoto_20211204_um_10.13.13_Small.jpeg_91c307bb.zip

1 Reply

VN Vignesh Natarajan Syncfusion Team December 6, 2021 10:00 AM UTC

Hi Niwa,  
 
Greetings from Syncfusion support.  
 
Query: “Search also for Value in MultiSelectFieldSettings with WhereFilter” 
 
We have analyzed your query and requirement to search the values with multiple field value. But we would like to inform you that it is not possible to filter a column in Grid with multiple fields value. Also we understand that you have rendered the MultiSelect component in a Text and Value pair.  
 
Either one of Fields value must match with the Grid column value. (i.e.) either ID property value must match the column data or Name property value must match column data. If there is not connection between these two table (i.e.) grid datasource and Multiselect dropdown data. Then it will not be possible filter the value in Grid column.  
 
We would like inform you that we have provided support for complex data and ForeignKey column to bind data from different datasource to Grid column. Kindly refer the below UG documentation for your reference 
 
 
Using above feature you have display the data in Grid column with text and value pair along with different data (ForeignKey). Also you can FilterTemplate with MultiSelect component for that column to achieve your requirement.  
 
 If we misunderstood your requirement, kindly get back to us with more details (grid code example and model class) along with relationship between two table data. It will be very helpful for us to validate the reported query at our end and provide solution as early as possible. 
 
Regards, 
Vignesh Natarajan  


Loader.
Up arrow icon