Hello,
I'd like to perform an action when a user clicks on a specific column and clears the filter.
so when user clicks on clear filter, and its a specific column, then do custom action.
I tried this code but it makes the entire page freeze
private void OnActionBegin(ActionEventArgs<OperationsSegmentModel> args)
{
var a = _grid.FilterSettings.Columns;
foreach (var v in a)
{
if (v.Field.Contains("LatestStep"))
{
if (args.RequestType.Equals(Action.ClearFiltering))
{
//custom bool
_isStepFiltered = false
}
}
else
{
_isStepFiltered = true
}
}
}
Hi Pavel,
Greetings from Syncfusion support.
currently we are validating the reported query at our. We need some more time to analyze your query. So we will update you the further details in two business days on or before August 18, 2022.
Until then we appreciate your patience.
Regards,
Monisha
Hi Pavel,
Thanks for the patience.
Query: “so when user clicks on clear filter, and its a specific column, then do custom action. I tried this code but it makes the entire page freeze”
We have checked your query and we could see that you have rendered foreach loop inside action begin event of Grid. We would like to inform that action begin will trigger for all data operation in Grid. For Example when we click filter icon it will trigger with request type filterbeforeopen, filterchoice count, filtering and so on. So that foreach loop will be triggered many times and the page become freeze. Instead we suggest you to check request type before rendering foreach loop.
Also we have confirmed an issue and logged the defect report “Action Event does not contains request for Clear filter in Excel” for the same. Thank you for taking time to report this issue and helping us to improve our product. At Syncfusion, we are committed to fix all validated defects (subject to technological feasibility and Product Development Life Cycle) and this fix will be included in our upcoming patch release which is expected to be rolled out on or before 14th September, 2022.
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.
Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization”
Until then we appreciate your patience.
Regards,
Monisha S
Thank you for your reply.
Is there any work around for now to capture when a user clicks clear filter on a particular column?
Hi Pavel,
Welcome.
Query: “Is there any work around for now to capture when a user clicks clear filter on a particular column?”
Currently we don’t have any other ways to find the excel clear filter in C# side. Kindly share us whether an javascript solution to find the clear filter click is ok at your end. If So we will check the possibilities of achieving your requirement at our end. Also share us the operation need to be performed inside an clear filter request.
Kindly get back to us if you have further queries.
Regards,
Monisha
Hello, A javascript solution could be useful until a fix is released.
thank you
Hi Pavel,
Thanks for the update.
Query: “A javascript solution could be useful until a fix is released.”
We have achieved your requirement by using JavaScript solution. Here we have invoked an method from JavaScript to C# when clear filter is clicked. Based on the click event we have update an Boolean variable. Kindly check the attached sample and code snippet for additional information.
@inject IJSRuntime Runtime
@IsClearFilterClicked
<SfGrid @ref="Grid" ID="DetailGrid" AllowFiltering="true" DataSource="@Employees">
</SfGrid>
@code{ SfGrid<EmployeeData> Grid; public EmployeeData target { get; set; } public bool firstrender { get; set; } = true; public async Task ActionBegin(ActionEventArgs<EmployeeData> args) { if(args.RequestType == Syncfusion.Blazor.Grids.Action.FilterBeforeOpen) { var dotNetReference = DotNetObjectReference.Create(this); // create dotnet ref await Runtime.InvokeAsync<string>("filter", dotNetReference); } }
bool IsClearFilterClicked = false; [JSInvokable("ClearFilter")] // method called from JS when clear filter is done public void ClearFilter() { IsClearFilterClicked = true; }
} |
var dotnetInstance;
function filter(dotnet) { dotnetInstance = dotnet; // dotnet instance to invoke C# method from JS }
document.addEventListener('click', function (args) { if(args.target.ariaLabel == "Clear Filter") { dotnetInstance.invokeMethodAsync('ClearFilter'); // call C# method from javascript function } })
|
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ServerApp-381434238.zip
Please let us know if you have any concerns.
Regards,
Monisha
Yes this is the correct solution but not working for me in Web Assembly. Can you please a sample for Web Assembly application instead of server?
Thank you
any updates?
thank you
Hi Pavel,
Thanks for the update.
Query: “Yes this is the correct solution but not working for me in Web Assembly. Can you please a sample for Web Assembly application instead of server?”
We have prepared the same application in WASM and it is working at our end. Kindly check the attached sample for your reference.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGrid-1837913918.zip
Please let us know if you have any concerns.
Regards,
Monisha
Hi Pavel,
We are glad to announce that, we have included the issue “Action Event does not contains request for Clear filter in Excel” in our latest release. So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the Nuget package for latest fixes and features from below.
Nuget : https://www.nuget.org/packages/Syncfusion.Blazor.Grid
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.
Regards,
Monisha