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

detailtables colapses after checkbox checked changed

1 Answer 64 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dino
Top achievements
Rank 1
dino asked on 12 Aug 2010, 02:22 PM
Hi,

I have a Radgrid that has a DetailTable. Inside the of the Master I have an ItemTemplate Column that contains a checkbox. Same for the GridDataView of the DetailTable. On CheckedChanged I run a simple update query, and then rebind the RadGrid. When the rebind is done I find that the GridView is colapsed. I could use item.OwnerTableView.Rebind() on the same event instead of rebinding the whole grid. This fixes the problem for the detail Tables but if the checkbox belongs to the master tablethen i get the same effect collapsing effect. Does anyone knows how to overcome this?

Thanks in advance!
 

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 17 Aug 2010, 04:05 PM
Hi dino,

When you rebind a GridTableView, the latter re-creates and re-initializes all its items. Thus, freshly recreated items have all their default settings and you lose the previous Expanded or Selected state. When you rebind a nested GridTableView the parent table's Items are not affected, that is why you are getting the detail table visible after rebinding. This is not the case with child items of the rebound table, however. If you rebind the MasterTableView, you will get all the child items gone.

To prevent this behavior, you have to persist the expanded state of your grid items prior to rebinding. Then you can restore the expanded state to the rebound grid items. I have attached a small test page demonstrating one approach you can use to do that. For each GridTableView object (both nested and hierarchical), I use its Load and DataBound events. The first event gives me access to all the expanded items. What I do in the Load event of the GridTableView is:

1. Loop over all expanded items

2. Build a unique key for each item. I want the key to uniquely identify the item in the set of all hierarchical items in all levels, so I need to use a combination of the owner table UniqueID, as well as the item's data key values. I cannot simply use ItemIndex, ItemIndexHierarchical, or UniqueID of the item, because these do not identify the data record the item is databound to. If I delete an item from the table, my key will point to another data record. Therefore I need to use the data key names.

3. Save the unique key to the Session or ViewState.

Now, I have saved all the expanded items. I can identify them and restore their Expanded state even if the GridTableView rebinds. That's what I do in the DataBound event handler:

1. Loop over all grid items
2. Build their unique keys used to save their expanded state.
3. Check if the item's unique key exists in the set all saved keys. If it does, set the items Expanded state to true

The approach gives me the convenience of keeping all items' Expanded state consistent even on rebind. You can rebind different detail tables (using the Refresh button in the command item) to see the expanded items' state is preserved.

Regards,
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
dino
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or