# How can I store sorting info before grid is reloaded?

**URL:** <https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376>\
**Category:** Radzen.Blazor Components\
**Created:** [March 18, 2022, 9:28am UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376 "2022-03-18T09:28:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Flippowitsch](https://forum.radzen.com/letter_avatar_proxy/v4/letter/f/ebca7d/32.png) [@Flippowitsch](https://forum.radzen.com/u/Flippowitsch)\
**Post date:** [March 18, 2022, 9:28am UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376/1 "2022-03-18T09:28:36Z")

</div>

I have the following grid:

```auto
<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

```auto
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:

```auto
_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

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [March 18, 2022, 10:55am UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376/2 "2022-03-18T10:55:49Z")

</div>

> [@Flippowitsch](#):
>
> `SortOrder="SortOrder.Ascending"`

You should bind this to a variable

---

<div class="post-metadata">

**Author:** ![Flippowitsch](https://forum.radzen.com/letter_avatar_proxy/v4/letter/f/ebca7d/32.png) [@Flippowitsch](https://forum.radzen.com/u/Flippowitsch)\
**Post date:** [March 18, 2022, 11:56am UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376/3 "2022-03-18T11:56:39Z")

</div>

I tried it with

```auto
@bind-SortOrder="@_fooSortOrder"

```

and

```auto
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](https://forum.radzen.com/uploads/default/original/2X/e/ed78d1295fac1e75e3c79f8be87a5bc41463cf78.png)  
This is necessary because I also must store the sort info about column "bar" for the case the user sorts by this column.

```auto
@bind-SortOrder="@_barSortOrder"

```

and

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

```

Thanks again

Philipp

---

<div class="post-metadata">

**Author:** ![enchev](https://forum.radzen.com/user_avatar/forum.radzen.com/enchev/32/16_2.png) [@enchev](https://forum.radzen.com/u/enchev)\
**Post date:** [March 18, 2022, 12:15pm UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376/4 "2022-03-18T12:15:31Z")

</div>

> [@Flippowitsch](#):
>
> `SortOrder="@_fooSortOrder"`

Just set the property

---

<div class="post-metadata">

**Author:** ![Flippowitsch](https://forum.radzen.com/letter_avatar_proxy/v4/letter/f/ebca7d/32.png) [@Flippowitsch](https://forum.radzen.com/u/Flippowitsch)\
**Post date:** [March 21, 2022, 12:07pm UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376/5 "2022-03-21T12:07:22Z")

</div>

But in column Foo, I need

```auto
SortOrder="@_fooSortOrder"

```

and in column Bar

```auto
SortOrder="@_barSortOrder"

```

With

```auto
private Radzen.SortOrder _fooSortOrder;
private Radzen.SortOrder _barSortOrder;

```

this leads to

 ![image](https://forum.radzen.com/uploads/default/original/2X/2/2e43e751066f2ee695ae051efbcfda54a9bfa0fa.png)  
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

> [@enchev](#):
>
> You should bind this to a variable

---

<div class="post-metadata">

**Author:** ![Flippowitsch](https://forum.radzen.com/letter_avatar_proxy/v4/letter/f/ebca7d/32.png) [@Flippowitsch](https://forum.radzen.com/u/Flippowitsch)\
**Post date:** [March 22, 2022, 8:37am UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376/6 "2022-03-22T08:37:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bnn678](https://forum.radzen.com/user_avatar/forum.radzen.com/bnn678/32/10034_2.png) [@bnn678](https://forum.radzen.com/u/bnn678)\
**Post date:** [March 22, 2022, 6:22pm UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376/7 "2022-03-22T18:22:54Z")

</div>

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

> [@Event Callbacks for Sort and Page Events from DataGrid](http://forum.radzen.com/t/event-callbacks-for-sort-and-page-events-from-datagrid/10400/2):
>
> You can use LoadData to get info about sorting, paging, filtering etc. check our demos for reference. UPDATE: Actually we've decided to add such events: [DataGrid Sort, Filter and Page events added · radzenhq/radzen-blazor@048de25 · GitHub](https://github.com/radzenhq/radzen-blazor/commit/048de253a9ac13cf14dff88824c062e5e9afced3)

---

<div class="post-metadata">

**Author:** ![Flippowitsch](https://forum.radzen.com/letter_avatar_proxy/v4/letter/f/ebca7d/32.png) [@Flippowitsch](https://forum.radzen.com/u/Flippowitsch)\
**Post date:** [March 23, 2022, 10:17am UTC](https://forum.radzen.com/t/how-can-i-store-sorting-info-before-grid-is-reloaded/10376/8 "2022-03-23T10:17:25Z")

</div>

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