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

Grid Expanded State

4 Answers 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JSON
Top achievements
Rank 1
JSON asked on 20 May 2010, 08:02 PM
Hello again,

How do you retain the current expanded state of a radgrid after navigation to another page. I know I can do so by envoking Javascript "history" but must thumb through the cached pages to return. Using "Response.Redirect" returns to a clapsed grid.

 Thank you,

Steve O...
 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 May 2010, 08:54 AM
Hello Steve,

Take a look at the documentation where a similar approach is described for persisting the selected items on postback. Here uses a session variable to store the key values for the selected row and in prerender event traverse through the rows of the grid and select the item. Try the same logic for setting Expanded property instead of Selected as in documentation.

Also the example in the forum post will shed some light on how to perform that.

Regards,
Shinu.
0
JSON
Top achievements
Rank 1
answered on 21 May 2010, 06:56 PM
Hello,

Not sure how to apply either example to my situation. With three detail levels I was not able to identify a specific detail item selected in the hierarchy.

Each attempt produced a nested view item index of -1?

Thank you,

Steve O...


 

protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

ArrayList selectedItems;

 

 

if (Session["selectedItems"] == null)

 

{

selectedItems =

new ArrayList();

 

}

 

else

 

{

selectedItems = (

ArrayList)Session["selectedItems"];

 

}

 

if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)

 

{

 

GridDataItem dataItem = (GridDataItem)e.Item;

 

 

string dataView = dataItem.OwnerTableView.Name.ToString();

 

 

switch (dataView)

 

{

 

case "Incidents":

 

 

if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)

 

{

 

string IncidentID = dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["IncidentID"].ToString();

 

selectedItems.Add(IncidentID);

Session[

"selectedItems"] = selectedItems;

 

}

 

break;

 

 

 

case "Units":

 

 

if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)

 

{

 

string UnitId = dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["UnitId"].ToString();

 

selectedItems.Add(UnitId);

Session[

"selectedItems"] = selectedItems;

 

}

 

 

break;

 

 

case "UnitLogs":

 

 

if (e.CommandName == RadGrid.ExpandCollapseCommandName && e.Item is GridDataItem)

 

{

 

string UnitLogId = dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["UnitLogId"].ToString();

 

selectedItems.Add(UnitLogId);

Session[

"selectedItems"] = selectedItems;

 

}

 

 

break;

 

 

default:

 

 

break;

 

}

}

}


 

protected void RadGrid2_PreRender(object sender, EventArgs e)

 

{

 

 

if (Session["selectedItems"] != null)

 

{

 

 

ArrayList selectedItems = (ArrayList)Session["selectedItems"];

 

 

 

Int16 stackIndex;

 

 

 

for (stackIndex = 0; stackIndex <= selectedItems.Count - 1; stackIndex++)

 

{

 

 

string curItem = selectedItems[stackIndex].ToString();

 

 

 

GridTableView nestedTableView = (RadGrid2.MasterTableView.Items[0] as GridDataItem).ChildItem.NestedTableViews[0];

 

 

 

foreach (GridNestedViewItem nestedViewItem in nestedTableView.GetItems(GridItemType.NestedView))

 

 

{

 

 

if (nestedViewItem is GridNestedViewItem)

 

{

 

 

GridNestedViewItem dataItem = (GridNestedViewItem)nestedViewItem;

 

 

 

string dataView = dataItem.OwnerTableView.Name.ToString();

 

 

 

if (dataItem.ItemIndex >= 0)

 

{

 

 

switch (dataView)

 

{

 

 

case "Units":

 

 

 

if (curItem.Equals(dataItem.OwnerTableView.DataKeyValues[dataItem.]["UnitId"].ToString()))

 

{

dataItem.Selected =

 

true;

 

 

 

break;

 

}

 

 

break;

 

 

 

case "UnitLogs":

 

 

 

if (curItem.Equals(dataItem.OwnerTableView.DataKeyValues[dataItem.ItemIndex]["UnitLogId"].ToString()))

 

{

dataItem.Selected =

 

true;

 

 

 

break;

 

}

 

 

break;

 

 

 

default:

 

 

 

break;

 

}

}

}

}

}

}

}

 



0
JSON
Top achievements
Rank 1
answered on 24 May 2010, 06:21 PM
Still waiting for some help!
0
Pavlina
Telerik team
answered on 26 May 2010, 03:08 PM
Hello Steve,

Go through the following code library submission which demonstrates how to retain the expanded/collapsed state and see whether it helps:
Retain expanded/selected state in hierarchy on rebind

Best wishes,
Pavlina
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
JSON
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
JSON
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or