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

griddataitem.set_expanded() doesn't work

1 Answer 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Software
Top achievements
Rank 1
Software asked on 03 Jul 2008, 10:58 PM
I'm trying to expand and collapse my nested views all on the client since it typically takes 4-5 seconds just to collapse a row on the server side, and it doesn't even have to retrieve data!  So I added a javascript function to the OnRowClick client event:
function rgWtsRowClick(sender, args) {    
    var idx = args.get_itemIndexHierarchical();  
    var currentItem = sender.get_masterTableView().get_dataItems()[idx];  
 
    if(currentItem.get_selected()) {  
        currentItem.set_selected(false);  
        currentItem.set_expanded(false);  
    } else {  
        currentItem.set_selected(true);  
        currentItem.set_expanded(true);  
    }  
}  
 
I used the get_selected because I wasn't getting anything from the get_expanded.  But get_selected works, and set_selected works.  In either case, set_expanded does NOT work and I can't figure out why.  It's driving me NUTS.  I also tried setting the state from the masterViewTable using expandItem and collapseItem, but those don't work and I suspect it has something to do with the HierarchyLoadMode not being set to Client. 

Another bit of info: I'm setting the data in the nested view on the server side in the OnItemCommand method.  I check to see if the command name is "RowClick" or "ExpandCollapse" and get the data based on that.  I was expanding or collapsing the rows there too, but I found that even when I didn't have to retrieve the data and all I had to do was collapse the row, it still took 4-5 seconds.  That's just not acceptable, so I'm hoping this solution will go much quicker...?

Is there SOME example of how this works somewhere?  I have to get this project done by Friday and I can't get Telerik to respond to my support tickets.  I could really use some help...

Thanks,  eddie

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 07 Jul 2008, 11:26 AM
Hello Eddie,

Please note that the client data item object will not expand properly after set_expanded(true), if RadGrid's MasterTableView does not have its HierarchyLoadMode set to "Client". After setting that property, the simplest way of expanding an item on row click would be the following:

function RowClick(sender, args) 
    args.get_gridDataItem().set_expanded(!args.get_gridDataItem().get_expanded()); 
 
    var item = sender.get_masterTableView().get_dataItems()[args.get_itemIndexHierarchical()]; 
    var masterTableView = sender.get_masterTableView(); 
    var rowIndex = args.get_itemIndexHierarchical(); 
     
    if(item.get_expanded())  
    {    
        var imageButtonPath = masterTableView.getCellByColumnUniqueName(masterTableView.get_dataItems()[rowIndex], "ExpandColumn").innerHTML
        imageButtonPath = imageButtonPath.replace("title=\"Expand\" class=\"rgExpand\"","title=\"Collapse\" class=\"rgCollapse\""); 
        masterTableView.getCellByColumnUniqueName(masterTableView.get_dataItems()[rowIndex], "ExpandColumn").innerHTML = imageButtonPath; 
    }  
    else  
    {  
        var imageButtonPath = masterTableView.getCellByColumnUniqueName(masterTableView.get_dataItems()[rowIndex], "ExpandColumn").innerHTML
        imageButtonPath = imageButtonPath.replace("title=\"Collapse\" class=\"rgCollapse\"","title=\"Expand\" class=\"rgExpand\""); 
        masterTableView.getCellByColumnUniqueName(masterTableView.get_dataItems()[rowIndex], "ExpandColumn").innerHTML = imageButtonPath; 
    }  

The actual expanding/collapsing is done on the first line of code in the RowClick method. The lines following it set the proper expand/collapse image (plus,minus sign) in the expand column.

I need to mention that when RadGrid is expanding on the server, the current item's detail table is rebound to its data before being shown, therefore if HierarchyLoadMode is set to ServerOnDemand (also the default value), after each press of the expand button, the expanded item is first databound. Therefore if you have heavy data load nested inside your detail tables, you may expect RadGrid to slow down during expand.

Our Support team would be glad to help you solve the difficulties you are experiencing. What you can do, if convenient for you, is to provide us with a sample runnable project attached to an official support ticket, so that we can advise you further. On the other hand, please check your account, to see that all of your support communication has been answered to.

Regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Grid
Asked by
Software
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or