Hello,
I am trying to customize Grid toolbar with few radio buttons keeping default 'search' functionality. I used RenderFragment method to add 2 radio buttons followed by 'Search' in the toolbar. Buttons are displayed and their callback works, but I am not able to refresh Grid data based on radio selection.
I also looked at template method, but with that I am not able to integrate default 'Search' function in the toolbar.
@code {
private static string SchemeTypeCheckedValue = "a";
private SfGrid<OrderData> Grid;
private List<Object> Toolbaritems = new List<Object>() {
new ItemModel() { Type = ItemType.Button, Template = AditionalOps}, "Search"
};
public List<OrderData> Orders { get; set; }
protected override void OnInitialized()
{
Orders = OrderData.GetAllRecords();
}
private static RenderFragment AditionalOps => @<div>
<SfRadioButton TChecked="string" Label="VICTE" Name="SchemeTypeOptions" Value="v" onchange="@OnRadioButtonChange">
</SfRadioButton>
<SfRadioButton TChecked="string" Label="SUPRD" Name="SchemeTypeOptions" Value="s" onchange="@OnRadioButtonChange">
</SfRadioButton>
</div>;
private static void OnRadioButtonChange(Microsoft.AspNetCore.Components.ChangeEventArgs args)
{
Console.WriteLine("OnRadioButtonChange start");
SchemeTypeCheckedValue = args.Value as string ?? string.Empty;
String message = $"Selected Scheme Type: {SchemeTypeCheckedValue}";
// How to trigger GetAllRecords() method to refresh data since static method can not access Orders variable.???
Console.WriteLine(message);
}
Hi Sandip,
We checked your query and understand that
you want to filter data using radio buttons while keeping the default 'Search'
functionality in the Syncfusion Blazor Grid toolbar. We recommend referring to
the API documentation for guidance. You can use the built-in toolbar
functionality in the custom toolbar with radio buttons by calling programmatic
methods. In the radio button change event, we have filtered the Grid using the
SearchAsync() method. Please refer to the code snippet and sample provided for
your reference.
Sample : https://blazorplayground.syncfusion.com/embed/rthojKMDJhJKvpKp?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5
|
private static void OnRadioButtonChange(Microsoft.AspNetCore.Components.ChangeEventArgs args) { Console.WriteLine("OnRadioButtonChange start"); SchemeTypeCheckedValue = args.Value as string ?? string.Empty; String message = $"Selected Scheme Type: {SchemeTypeCheckedValue}"; Grid.SearchAsync(SchemeTypeCheckedValue); Console.WriteLine(message); } |
Please get back to us if you need further assistance.
Regards,
Naveen Palanivel.
Hi Naveen,
Thanks.
I can see that you changed Grid variable to static as
Based on your query, we have removed the static type and used a non-static approach. And we attempted to reproduce the issue where the data was not reflected in the grid. However, we were unable to replicate the reported issue. For your reference, we have attached a simple sample. To further investigate the problem, we require additional clarification from your end. Please provide the following details to help us proceed further.
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.
Thanks. This works.
Refresh issue in my case was arising because I was modifying grid datasource directly as Grid.DataSource=GetAllRecords(). I could achieve required result by resettting grid by calling Grid.ResetPersistDataAsync() instead of Grid.Refresh().
But, now I modified code to change razor page level data (Orders) as done by you, and now Grid.Refresh() achieves required result. Thanks a
Thanks for the update. We are happy to hear that the
issue has been resolved on your end. Please feel free to reach out if you have
any further queries regarding this issue.