My problem is the following:
I use a RadGridView to display data for the user and our project is designed with MVVM. it's possible to get the SORTINGSTATE for each column of the GridView, but I find no possibilty to get the position of the sorted column. Because in a GridView it's possible to sort more than one column and so I need the order of the sorted columns.
What I need is:
- all sorted columns of a GridView
- for each column the sortingstate (ascending/descending)
- for each column the sorting position
Has anyone a idea how I can get the sort position for each column??
Best regards, Richard
5 Answers, 1 is accepted
You may walk through the columns collection of the grid and check each of the column's sorting state by the corresponding property - SortingState. Considering the order of the columns, you may use the property - DisplayIndex.
Maya
the Telerik team
thanks for your answer.
I tried the displayindex, but it's only the index of the column on which position in the grid the column is displayed. What I needed, was an index for the sorting order, but I have already found a solution.
Now I created a DICTIONARY list of type <string,SortingState>. If the user now clicks onto a column header for sorting, the SORTING event of the RadGridView is called. There I add the column (fieldname) and the sortingstate into my dictionary. So I get a list of my fieldnames in the right sorting order.
One strange thing is still apearing ... if I normally click onto the first column for sorting a additional sign " ^ " is displayed, but if I make a Binding on SORTINGSTATE and set the binding variable in MVVM the sign is not shown. It looks like the GridColumns doesn't really work, if using Bindings on their properties. There are also problems with setting the WIDTH and ISVISIBLE.
best regards, Richard
May you reveal some more details about your exact requirements and expected behavior ? Why do you require to bind the SortingState ? What is the expected by your behavior ?
Considering the binding to isvisible and width properties - again it depends on you settings and requirements.
Maya
the Telerik team
I had an idea to use one GridView to display several different tables depending on a button you can click. So I would have had to change the displayed columns and settings (width or sorting). But I don't need it anymore, thanks for your answer.
Regards, Richard
In case you decide to follow up your initial idea, you may implement the approach presented in our Save and Load GridView Layout article and example. Thus you will be able to keep the desired information about the settings of a particular grid and load it afterwards.
Maya
the Telerik team