How can I store sorting info before grid is reloaded?

I have the following grid:

<RadzenDataGrid @ref="_dataGrid" Data="IFilteredDataS"
    AllowSorting="true" TItem="Data" @bind-Value="SelectedData">
    <Columns>
        <RadzenDataGridColumn Property="Foo"
            SortOrder="SortOrder.Ascending" TItem="Data">
            <HeaderTemplate>Foo</HeaderTemplate>
        </RadzenDataGridColumn>
        <RadzenDataGridColumn Property="Bar" TItem="Data">
            <HeaderTemplate>Bar</HeaderTemplate>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

with

public IList<Data> SelectedData { get; set; }
public IEnumerable<Data> IFilteredDataS { get; set; }

There are Radzen Range Sliders to filter the grid data and if the user does so, the grid is emptied and new data is loaded:

_filteredDataS.Clear();
_suitableDataS.ForEach((item) =>
{
    _filteredDataS.Add(item);
});
IFilteredDataS = _filteredDataS;
_dataGrid.Reload();

My problem is, that when the user sorts by column "Bar", after reloading the grid, data is sorted by the default column "Foo". Is there way to
  • either avoid this or
  • store sort column and sort order and set it after reload?

Many thanks

Philipp

You should bind this to a variable

I tried it with

@bind-SortOrder="@_fooSortOrder"

and

private Radzen.SortOrder _fooSortOrder = Radzen.SortOrder.Ascending;

but get the unhandled error

Radzen.Blazor.RadzenDataGridColumn does not have a property matching the name 'SortOrderChanged'


In addition: How can I store "not sorted"? The enum only allows ascending and descending
image
This is necessary because I also must store the sort info about column "bar" for the case the user sorts by this column.

@bind-SortOrder="@_barSortOrder"

and

private Radzen.SortOrder _barSortOrder = Radzen.SortOrder.NOTSORTED;

Thanks again

Philipp

Just set the property

But in column Foo, I need

SortOrder="@_fooSortOrder"

and in column Bar

SortOrder="@_barSortOrder"

With

private Radzen.SortOrder _fooSortOrder;
private Radzen.SortOrder _barSortOrder;

this leads to
image
The indicators depict ascending order but the columns are not sorted.

Also, whenever I break my app, _fooSortOrder and _barSortOrder are always Ascending. There is no binding and therefore, I cannot store the value. That's why I tried @bind-SortOrder="@_fooSortOrder, when you recommended

This morning I tried to achieve storing the sorting info with @ref at the RadzenDataGridColumn but was not successful. I am running out of ideas...
Is there a solution or is it simply not possible to store sorting information?

With the recent addition of the DataGridColumnSortEventArgs I believe you could manually handle the sort events to resolve your issue. The new events haven't been released yet, but I suspect they will be in the next release

Nice!
I will try, when the next update is published...