Radzen Datagrid sorting reset

I have a little problem with the data grid. Let's say for example I have a grid with a sorted column in ascending order. I click a button that will add some data into the Database. I then fetch the whole list from the API to get the most recent change. I would expect that the DataGrid add this new items and still keep the sorting but it is not the case. Am I missing something here?
Here is a sample code that show this behavior.

<RadzenDataGrid TItem="Items" Data="@listItems" AllowSorting="true" Count="@listItems.Count">

    <Columns>
        <RadzenDataGridColumn TItem="Items" Property="name">

        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

<RadzenButton Click="add">Add</RadzenButton>
<RadzenButton Click="edit">Edit</RadzenButton>
@code {
    class Items
    {
        public string name { get; set; }
        public int age { get; set; }
    }

    List<Items> listItems = new List<Items>();

    protected override void OnInitialized()
    {
        base.OnInitialized();
        var item = new Items()
            {
                name = "samuel",
            };

        listItems.Add(item);
    }

    private void add()
    {
        var updatedList = new List<Items>()
            {
            new Items() { name = "samuel"},
            new Items() { name = "marco"}
            };

        listItems = updatedList;
    }

    private void edit()
    {
        var updatedList = new List<Items>()
        {
            new Items() { name = "test"},
            new Items() { name = "marco"}
        };
        listItems = updatedList;
    }
}

No, the DataGrid will reset everything when you assign new value to Data.

Is there a way to store the setting and then reapply the sorting after the new value is added

Yes, there are demos for saving and restoring settings like sorting, filtering, paging, etc.

1 Like

Where to find demo of saving settings after adding data?

There is no such demo.