DataGridColumn programmatically set sort direction

Hello Radzen Team!

I have this one table that will easily store 10.000.000+ items. The items are retrieved with a click of a button, by chunks of 1.000 items per query. For this reason I don't want to query the database with an order by property, as it would considerably slow it down. However, right after (or while) the items are retrieved I want the DataGrid to be sorted by a specific column in a specific direction.

Any ideas?

Hi @kim,

Is your data IQueryable or you are using LoadData? Our DataGrid can work natively with IQueryable and sorting, filtering and paging will be executed directly on your database server. You will get PageSize data with sorting and filtering applied.

The data is IQueryable and is retrieved after inserting some filters and clicking a button:

This is the code that fills the accesses List:

for (int i = 0; i <= queries; i++) {
    accesses.AddRange(await Global.Services.DatabaseService.ReadList<Global.Models.Access>($"where={string.Join(" AND ", where)}", $"limit={(total-i*1000 > 1000 ? 1000 : total-i*1000)}", $"offset={i*1000}"));
    current = accesses.Count();
}

In this case you can execute OrderBy() for the IQueryable just before assigning the data to the DataGrid. Unfortunately there is no API that can be used to tell the grid to display the sorting direction icon for the column.

1 Like

Good idea! This might confuse the users a little bit, but it's fast.