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

Accessing Proper Row From OnCommand With Collapsed Group Row

1 Answer 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shawn R.
Top achievements
Rank 1
Shawn R. asked on 10 Aug 2016, 10:44 PM

I have a GridButtonColumn with ButtonType="ImageButton". I'm accessing the button click client side with OnCommand of the RadGrid.

<ClientSettings >
   <ClientEvents OnCommand="OnCommand" />
</ClientSettings>

 

I know I can get the row through args.get_commandArgument(), but this is the row of the Master Table and works fine if my grouped table doesn't have a collapsed grouping, but fails horribly when there is a collapsed group.

 

<script type="text/javascript">
    function OnCommand(sender, args) {
        var rowIndex = args.get_commandArgument(); // getting row index
        var itemValue = masterTable.getCellByColumnUniqueName(masterTable.get_dataItems()[row], "itemName").innerHTML;
       }
</script>

 

For example, the rowIndex is determined to be 20 and and there are no collapsed rows so masterTable.getCellByColumnUniqueName(masterTable.get_dataItems()[row], "itemName").innerHTML return the correct row and value. But say a group above has 10 rows collapsed then the 20 referes to something 10 down the table. The rowIndex value in this instance needs to be 10. 

 

So . . . what am I doing wrong. How to account for the collapsed rows? Should I be doing this differently?

 

TIA - Shawn

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 15 Aug 2016, 11:55 AM
Hi Shawn,

You can try the following alternative approach:
<telerik:GridTemplateColumn UniqueName="TemplateColumnName">
    <ItemTemplate>
        <asp:ImageButton ID="ImageButton1" runat="server" AlternateText="ImageButtonCommand"
            OnClientClick='<%# "imageButtonClick(\""+Eval("ShipName")+"\"); return false;" %>' />
    </ItemTemplate>
</telerik:GridTemplateColumn>
JavaScript:
function imageButtonClick(shipName) {
    var masterTable = $find('<%= RadGrid1.ClientID %>').get_masterTableView();
    masterTable.fireCommand("ImageButtonCommand", shipName);
}

I hope this will prove helpful.

Regards,
Eyup
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Shawn R.
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or