Hi, I am trying to use a MultiSelect component as my Filter Template in my Data Grid Column.
Whenever I select some filter items in the MultiSelect, after filtering out those items, if I come back to the MultiSelect component, it does not save those chosen filtered items.
As you can see in the video, I chose 'Bulzi Admin' & 'Damage_Control' as my filter choices under 'Groups', but it clears those items when I move back into the filter.
Question 1:
How can I make MultiSelect save the chosen filter items in a Data Grid Column Filter Template?
pt1
pt2
Question 2:
I want the Filter operation for FilterType.Menu in my 'Groups' column to only have the operation 'Equal To' and nothing else. How can I make this the only operation for the Filter Menu?
Thank you.
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true" AllowPaging="true" Height="375">
<GridEvents OnActionBegin="ActionBeginHandler" TValue="Order"></GridEvents>
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.CheckBox"></GridFilterSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" FilterSettings="@(new FilterSettings{Type = Syncfusion.Blazor.Grids.FilterType.Menu })" Width="150">
<FilterTemplate>
<SfMultiSelect TValue="string[]" TItem="Customer" Mode="VisualMode.CheckBox" ID="CustomerID" Value="@FilteredValues.ToArray()"
Placeholder="Customer" DataSource="@LocalData">
<MultiSelectFieldSettings Text="Text" Value="Text"></MultiSelectFieldSettings>
<MultiSelectEvents ValueChange="OnChange" TValue="string[]" TItem="Customer"></MultiSelectEvents>
</SfMultiSelect>
</FilterTemplate>
</GridColumn>
. ..
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid;
public List<Order> Orders { get; set; }
bool IsClearFilter { get; set; }
List<string> FilteredValues = new List<string>(); // for maintaining filtered values
. . .
public async Task OnChange(MultiSelectChangeEventArgs<string[]> args)
{
if(args.Value?.Length > 0)
{
FilteredValues = args.Value.ToList();
await Grid.FilterByColumn("CustomerID", "equal", args.Value.ToList(), "or");
} else
{
FilteredValues = new List<string>();
IsClearFilter = true;
await Grid.ClearFiltering();
}
}
public void ActionBeginHandler(ActionEventArgs<Order> args)
{
if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Filtering))
{
if (args.CurrentFilteringColumn == null)
{
FilteredValues = new List<string>();
IsClearFilter = false;
}
}
}
} |
Hi, there is a problem in your solution:
After selecting a value in the MultiSelect component, and clicking outside of the component, the data grid column 'Groups' is filtered correctly. However, if I click 'Filter' with the same value still selected in the MultiSelect, the data grid will filter again and removes the top record.
Question:
Why does the data grid filter twice after filtering through the MultiSelect and then pressing 'Filter' on the FilterType.Menu? And how do I prevent this from filtering twice?
I've attached a video on the problem.
Thank you
Attachment: multiselect_bug2_3d06f839.zip
Hi, I reproduced a similar problem in the provided sample. As you can see in the video, the filter is glitchy and is filtering the wrong items. The multiselect filter was filtering 'ALFKI' when the selected filtered item was 'ANANTR'. This seems to occur when I first remove 'ALFKI' from the selected filtered list and selected 'ANANTR' after.
I am having similar problems in my filter because it is not filtering correctly.
|
public async Task OnChange(MultiSelectChangeEventArgs<string[]> args)
{
if(args.Value?.Length > 0)
{
FilteredValues = args.Value.ToList();
await Grid.FilterByColumn("CustomerID", "equal", FilteredValues, "or");
} else
{
FilteredValues = new List<string>();
//await Grid.ClearFiltering(); //removed this line
}
} |
Hi, thank you for your help.
I also want to filter the multi-select ONLY when the 'Filter' button is pressed and NOT when the user clicks outside of the multi-select component.
Question:
How do I filter ONLY when the 'Filter' button is pressed and not when the user clicks outside of the multi-select component?
Thank you
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true" AllowSorting="true" GridLines="GridLine.Both" AllowPaging="true" Height="375">
<GridEvents OnActionBegin="ActionBeginHandler" TValue="Order"></GridEvents>
. . .
<GridColumns>
. . .
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" FilterSettings="@(new FilterSettings{Type = Syncfusion.Blazor.Grids.FilterType.Menu })" Width="150">
<FilterTemplate>
<SfMultiSelect TValue="string[]" TItem="Customer" Mode="VisualMode.CheckBox" ID="CustomerID" Value="@FilteredValues.ToArray()"
Placeholder="Customer" DataSource="@LocalData">
<MultiSelectFieldSettings Text="Text" Value="Text"></MultiSelectFieldSettings>
<MultiSelectEvents ValueChange="OnChange" TValue="string[]" TItem="Customer"></MultiSelectEvents>
</SfMultiSelect>
</FilterTemplate>
</GridColumn>
. ..
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid;
public List<Order> Orders { get; set; }
List<string> FilteredValues = new List<string>();
. . .
bool IsFilterValueChange { get; set; }
public async Task OnChange(MultiSelectChangeEventArgs<string[]> args)
{
if(args.Value?.Length > 0)
{
FilteredValues = args.Value.ToList();
IsFilterValueChange = true;
//await Grid.FilterByColumn("CustomerID", "equal", FilteredValues, "or"); //remove this line here
} else
{
FilteredValues = new List<string>();
//await Grid.ClearFiltering(); //remove this line
}
}
public async Task ActionBeginHandler(ActionEventArgs<Order> args)
{
if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Filtering))
{
if (IsFilterValueChange)
{
IsFilterValueChange = false;
args.Cancel = true;
await Grid.FilterByColumn("CustomerID", "equal", FilteredValues, "or");
}
if (args.CurrentFilteringColumn == null)
{
FilteredValues = new List<string>();
}
}
}
} |
Hi thank you this worked.
However, there is a bug when popping off items from the filtered item list.
If I filter CustomerName by 'ALFKI' or 'ANANTR', I get the filtered list for both of those items.
However, if I remove 'ANANTR' after that, it will not provide me with the filtered list of only 'ALFKI' and shows the same
unmodified filtered list.
I have demonstrated this issue in the attached video.
Question:
How do I implement filtering the list as I pop off the various filter items from the filter list?
Thank you.
|
@code{
SfGrid<Order> Grid;
public List<Order> Orders { get; set; }
List<string> FilteredValues = new List<string>();
. . .
bool IsFilterValueChange { get; set; }
public async Task OnChange(MultiSelectChangeEventArgs<string[]> args)
{
if(args.Value?.Length > 0)
{;
FilteredValues = args.Value.ToList();
IsFilterValueChange = true;
} else
{
FilteredValues = new List<string>();
IsFilterValueChange = true;
}
}
public async Task ActionBeginHandler(ActionEventArgs<Order> args)
{
if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Filtering))
{
if (IsFilterValueChange)
{
IsFilterValueChange = false;
args.Cancel = true;
await Grid.ClearFiltering();
await Grid.FilterByColumn("CustomerID", "equal", FilteredValues, "or");
}
if (args.CurrentFilteringColumn == null)
{
FilteredValues = new List<string>();
}
}
}
} |
Hi thank you for your help.
One last thing:
I want my filter operators to only display "Equal" & "Not Equal" for CustomerID column. So remove all other filter operators (Greater Than, Greater Than Or Equal, Less Than, Less Than Or Equal)
Question: How to keep only "Equal" & "Not Equal" filter operators for the CustomerID column? Thank you.
|
<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true" AllowSorting="true" GridLines="GridLine.Both" AllowPaging="true" Height="375">
<GridEvents OnActionBegin="ActionBeginHandler" TValue="Order"></GridEvents>
. . .
</SfGrid>
@code{
SfGrid<Order> Grid;
public List<Order> Orders { get; set; }
. . .
public class Operators
{
public string Value { get; set; }
public string Text { get; set; }
}
public async Task ActionBeginHandler(ActionEventArgs<Order> args)
{
if (args.RequestType == Syncfusion.Blazor.Grids.Action.FilterBeforeOpen)
{
if (args.ColumnName == "CustomerID")
args.FilterOperators = new List<object>() {
new Operators() { Text = "Equal", Value = "equal" },
new Operators() { Text = "Not Equal", Value = "notequal" } };
}
if (args.RequestType.Equals(Syncfusion.Blazor.Grids.Action.Filtering))
{
. . .
}
}
|
Hi Rahul,
Thank you for your help so far.
Your implementation works for MultiSelect Dropdown, but it is not working for single DropDownList.
I have modified the sample project to include a bool "isSent" to describe if the order has been sent or not. The column contains a custom filter template with a DropDownList component.
I have set the only filter operator to "Equals", but it will still include "Equals" and "Not Equals" as the filter operators for the 'isSent' column.
Question:
How do I create custom filter operators for the DropDownList component?
Thank you