Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get_selectedItems()[0] on RadGrid returns null

I have a problem with the get_selectedItems() function. I use RadGrid from Telerik. Great controls, but now I stumbled on a bug which I can not solve.

When selecting a row, I call the RowSelectionChanged function on the client side and then I'll get an exception.

Could anyone tell me why sender.get_selectedItems()[0] is null while sender.get_selectedItems().length is at least 1?

<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
    <script type="text/javascript">

            function RowSelectionChanged(sender, eventArgs) {
            if (sender != null) {
                for (i = 0; i < sender.get_selectedItems().length; i++) { 
                    var it = sender.get_selectedItems()[i];     // it is null
                            var element =it.get_element();  // throws exception
                    }
                }
            }
    </script>

</telerik:RadCodeBlock>

<telerik:RadGrid ID="rgTest" runat="server" >
    <MasterTableView>
        <Columns>
            <telerik:GridClientSelectColumn UniqueName="ClientSelectColumn"  />
            <telerik:GridBoundColumn DataField="guid" />
        </Columns>
    </MasterTableView>
        <ClientSettings EnableRowHoverStyle="true">
        <ClientEvents OnRowSelected="RowSelectionChanged" />
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
</telerik:RadGrid>
like image 436
ArekBee Avatar asked Nov 28 '11 13:11

ArekBee


1 Answers

Function get_selectedItems() should be invoked NOT on RadGrid object but on MasterTableView object.

This code works for me:

<telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
    <script type="text/javascript">

        function RowSelectionChanged(sender, eventArgs) {
            if (sender != null) {
                var masterTable = sender.get_masterTableView();
                for (i = 0; i < masterTable.get_selectedItems().length; i++) { 
                    var it = masterTable.get_selectedItems()[i];     
                    var element =it.get_element(); 
                }
            }
        }

    </script>
</telerik:RadCodeBlock>
like image 82
ArekBee Avatar answered Oct 04 '22 19:10

ArekBee