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

Sorting and RadGrid1.SelectedIndexes

1 Answer 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Willem Kip
Top achievements
Rank 1
Willem Kip asked on 20 Jul 2010, 02:09 PM
Hi All,

For the visualization and selection of certain pages I use a RadGrid solution.
(The list is based on a recursive SharePoint SPSiteDataQuery on site.rootweb with Webs Scope = Recursive. )

One of the columns is made for "sorting"

This is a numeric (Editable) field in which the user can insert a number 1, 2, 3 etc.
This number is the order in which the selected information should come out of the Grid. 
See the radgrid.png for clarification

So if 5 items are selected and only two have a number, then these two have the highest "prio" and should be first in the
foreach (string gridIndex in NieuwsbrievenGrid.SelectedIndexes)
{ }

Additional info: User will only emphasize on the "important" items. The other selected items will not get a number so ordering here can just be "default"

How can I accomplish this.
I tried to use the GridSortExpression on the "itemVolgorde" column but this doesn't work..

Thank you in advance.

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 22 Jul 2010, 02:55 PM
Hi Willem,

Note that RadGrid does not guarantee the selected indexes will be in any given order. You cannot, by default, rely on RadGrid placing the selected items in any particular order. In fact, selected items (both on the server and the client) are ordered in the same order you select them!

Still, your scenario can be implemented, provided that you use client-side selection. With item selection, RadGrid keeps 2 internal arrays that contain data about the selected items. Array elements are added and removed to these arrays in the same order users click to select the items. This data is then sent to the server on postback and RadGrid builds its server-side SelectedIndexes / Items collection based on this data.

The above described RadGrid workings can be manipulated to send the selected item data ordered in the particular order we need. To implement your scenario, you need to:

1. Add the data field that specifies the priority of your items to the DataKeyNames and ClientDataKeyNames collection of the MasterTableView. Thus, this data will be available on the client.

2. Use RadGrid's client-side OnRowSelected event to manipulate the 2 internal selected indexes arrays so that thay are always ordered the way we need - having the prioritized items sorted in ascending order, keeping the rest of the selected items unordered.

To demonstrate this approach, I have attached a sample test page implementing this logic. Note how I need to specify the data field name that is used to prioritize the data items. Using the demonstrated approach, the selected items are always ordered by priority and the server-side SelectedItems / SelectedIndexes collection is also in sync.

Let me know how this works for you.

All the best,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Willem Kip
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or