I am using Telerik controls 2008 Q2 SP2.
By using Javascript, is there a way to expand all / collapse all a hierarchy grid that uses a NestedTableView instead of DetailTables?
By using a for loop I tried:
grdVenue.get_masterTableView().expandItem(i);
While this does expand the item the +/- image doesn't reflect the change.
Kind regards
Mark Eaton
8 Answers, 1 is accepted
Try the following javascript code to achieve the desired scenario.
JS:
function OnClientClick() |
{ |
var Grid = $find("<%= RadGrid2.ClientID %>"); |
var MasterTable=Grid.get_masterTableView(); |
for(var i=0;i< MasterTable.get_dataItems().length;i++) |
{ |
var row = MasterTable.get_dataItems()[i]; |
if(row.get_expanded() == false) |
{ |
row.set_expanded(true); |
} |
else |
row.set_expanded(false); |
} |
} |
Regards
Shinu.
This did expand / collapse everything but still the +/- isn't updated to reflect the change.
Is there a bit more work needed to achieve this?
Kind regards
Mark Eaton
The expand/collapse images still aren't being updated to reflect the change.
In addition I noticed that expand all works nicely.
However if I am to expand a single row by clicking the + image, then try collapse all it won't work. Collapse all only seems to work if I do an expand all.
What would I need to do to make these 2 things work?
Kind regards
Mark Eaton
One possible implementation in this setup would be to locate and click the images via a client side function. This may be something similar to this approach. Additionally, I will investigate the issue with the expand collapse images not properly updating their state.
Regards,
Yavor
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I checked the sample project and was able to modify it to fit a NestedViewTemplate.
My code is:
var GridVenueMasterView = ggrdVenue.get_masterTableView();
// As the grid is really only a reflection of EventVenueList, just use that array to count the number of rows
// Otherwise it expands the 'hidden' rows making for one ugly mess
for(var i = 0; i < EventVenueList.length; i++)
{
var expandColumnImage = GridVenueMasterView.get_dataItems()[i].get_element().cells[0].firstChild;
if((blnExpand && GridVenueMasterView.get_dataItems()[i].get_expanded() === false) || (blnExpand === false && GridVenueMasterView.get_dataItems()[i].get_expanded()))
{
expandColumnImage.click();
}
}
This code does show the correct expand/collapse image.
However it now presents a different problem. If a user has expanded 1 row, then clicks expand all, this scenario breaks. It is because the get_expanded() always returns false. As such they cannot collapse all either.
Is there a different approach I need to take to check if a row is already expanded? That way when expand all is clicked I won't try to expand it again.
Kind regards
Mark Eaton
The most straightforward approach in this case would be to use the client side api to expand the items. However, this would not update the images. I will escalate the issue to our dev team, and will update the thread as needed.
Sincerely yours,
Yavor
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
As this is Telerik functionality that isn't working as expected, can I expect to have this resolved for the 2008 Q3 release?
The Javascript expandItem() should update the image.
Kind regards
Mark Eaton
The issue is escalated to our developers already. We will do our best to have it fixed for the upcoming Q3 release, expected at the beginning of the next month.
Best regards,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.