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

Hierarchy grid expand all / collapse all using Javascript and NestedViewTemplate

8 Answers 371 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 01 Oct 2008, 01:23 AM
Hi

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

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Oct 2008, 07:37 AM
Hi Mark,

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.
0
Mark
Top achievements
Rank 1
answered on 01 Oct 2008, 11:27 PM
Hi 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
0
Mark
Top achievements
Rank 1
answered on 09 Oct 2008, 11:37 PM
It's been over a week and I'm still waiting for a reply!

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

0
Yavor
Telerik team
answered on 10 Oct 2008, 05:39 AM
Hi Mark,

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.
0
Mark
Top achievements
Rank 1
answered on 13 Oct 2008, 12:09 AM
Hi Yavor

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

0
Yavor
Telerik team
answered on 15 Oct 2008, 12:24 PM
Hello Mark,

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.
0
Mark
Top achievements
Rank 1
answered on 15 Oct 2008, 09:50 PM
Thanks Yavor for looking into this.

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
0
Nikolay Rusev
Telerik team
answered on 17 Oct 2008, 04:27 PM
Hello Mark,

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.
Tags
Grid
Asked by
Mark
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mark
Top achievements
Rank 1
Yavor
Telerik team
Nikolay Rusev
Telerik team
Share this question
or