This is a migrated thread and some comments may be shown as answers.

Problem with default sorting

3 Answers 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Francis
Top achievements
Rank 1
Francis asked on 06 Jul 2020, 12:00 PM

Hi !

I try to manage default sorting on my grid. I add this markup into the MasterTableView :

<SortExpressions>
    <telerik:GridSortExpression FieldName="Prenom" SortOrder="Descending"/>
</SortExpressions>

But the datas are not sorted and the code :

$find('RadGrid1').get_masterTableView().get_sortExpressions()

return an empy array.

Is it normal ?

3 Answers, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 09 Jul 2020, 08:53 AM

Hi Francis,

The way you set default sorting is correct and normally you should get the data sorted, see Declarative sort expressions

On the other hand, reaching the sort expressions on the client is only possible when the RadGrid is bound on the client-side. Therefore the get_sortExpressions() client method returns an empty array.

You can get the sort expressions on the server-side instead:

RadGrid1.MasterTableView.GetColumn("UniqueName").SortExpression.ToString();

Still, if the data is not sorted per the declared expression we would need to see more details on the current scenario. Please provide us the markup and the code-behind of the page containing the RadGrid so that we have a better overview and be able to troubleshoot the case.

Looking forward to your feedback!

Kind regards,
Doncho
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Francis
Top achievements
Rank 1
answered on 09 Jul 2020, 11:39 AM

Hi,

my scenario is to build a grid (who extent RadGrid) that works mainly in client. Si we manage the datasource ourselves with the client events Created and Command and the data (according to current filters, current sorts and current pagination) are loaded in JS with a WebApi call. Si I need, in Created client event, to know the current order.

0
Doncho
Telerik team
answered on 10 Jul 2020, 01:07 PM

Hi Francis,

Since the RadGrid is bound on the client-side, the default sort expressions should also be applied on the client-side.

One approach you can try is to use the GridCreated client-side event to set the predefined sort expressions, check out and try the approach in the Adding Sort and Filter Expressions with Client-side Binding article.

In such a scenario you will be able to get the sort expressions using the client-side API, see Client-Side Programming Overview
JS

grid.get_masterTableView().get_sortExpressions()
I hope that will prove helpful.

Kind regards,
Doncho
Progress Telerik

Tags
Grid
Asked by
Francis
Top achievements
Rank 1
Answers by
Doncho
Telerik team
Francis
Top achievements
Rank 1
Share this question
or