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

Get Current Index in Template

5 Answers 310 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 30 Jun 2008, 08:30 PM
Hi,

I want to call a client side script inside an ItemTemplate.
The function accepts 2 parameters, the ID and the index of the row.

I trigger all this by setting:

<ItemTemplate> 
      <div style="background-color:Gray; padding:5px"<href="#" onclick="openRadWindow('<%#DataBinder.Eval(Container.DataItem,"ID")%>'); return false;">Test</a> 
     </div> 
</ItemTemplate> 

As you can see, the second parameter is missing. I am inside a hira. Table. I want to get the index of the parent table inside the DataBinder. Is there a way to get the value?

Another solution I am searching for ist to get the current selected row via client API without eventargs.

In detail I just want to collapse the parent row and open a radwindows (which works already) when the button inside the template is clicked. Maybe you have another idea.

Thanks!
Chris

5 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 03 Jul 2008, 09:06 AM
Hello Christian,

You can get the value for the parent item cell in the data binder in the following way:

<%# DataBinder.Eval(Container.OwnerTableView.ParentItem.DataItem, "ProductID")%> 

If you need to collapse a RadGrid row before opening a RadWindow, you can attach to the client-side OnClientShow event handler of the RadWindowManager, and there collapse all RadGrid expanded items:

        function WindowShow(sender, args) 
        { 
            var dataItems = $find('RadGrid1').get_masterTableView().get_dataItems(); 
            for (var i=0; i< dataItems.length; i++) 
            { 
                dataItems[i].set_expanded(false); 
            } 
        } 


Sincerely yours,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Christian
Top achievements
Rank 1
answered on 03 Jul 2008, 10:28 AM
Hi,

I want to get the row ID / INDEX of the parent row, not a dataitem value via databinder.

Thanks,
Chris
0
Veli
Telerik team
answered on 03 Jul 2008, 10:57 AM
Hi Christian,

In this case you can replace the mentioned inline expression with the following:

<%# DataBinder.Eval(Container.OwnerTableView.ParentItem, "ItemIndex") %> 

or

<%# Container.OwnerTableView.ParentItem.ItemIndex %> 


Kind regards,
Veli
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Christian
Top achievements
Rank 1
answered on 05 Jul 2008, 12:45 PM
Hi,

dataItems[0].set_expanded(

false); 

do not collapse the item !? I get a reference, but nothing happens.

If I use:

$find(

"<%= RadGrid1.MasterTableView.ClientID %>").collapseItem(0);

it collapse but the "+/-" image button still is set to "-" what means, the grid thinks it´s still expanded ?!

Are there any bugs in set_expanded?

0
Veli
Telerik team
answered on 07 Jul 2008, 12:28 PM
Hello Christian,

The expand/collapse image does not automatically adjust when expanding or collapsing on the client. Here is a sample script to set the plus/minus image accordingly:

    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; 
    }  


Greetings,
Veli
the Telerik team

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