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

RadGrid Wrong Row Index - Upgrading Telerik

2 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ali
Top achievements
Rank 1
Ali asked on 21 May 2014, 03:09 AM
Hi,

We have been using an older version of Telerik components (Telerik.Web.UI 2010.3.1317.20) in our web application and now we're looking into the latest one trial to upgrade.

One problem we're facing now is that in the same implementation of a RadGrid, getting the index of the selected row was zero based in our existing code (older version of Telerik). However, implementing the same using the new version of Telerik (2014.1.513.40) will return an incremented result. 
For example, if the first row of the grid is selected, in the old version the index value was zero, but in the new version it returns 1.

This is the implementation of my RadGrid:
<telerik:RadGrid GridLines="none" ID="RadGrid1" runat="server"
        AllowMultiRowSelection="true"
        AllowPaging="true"
        AllowCustomPaging="true"
        AllowSorting="true"
        AllowAutomaticDeletes="true"
        AutoGenerateColumns="true"
        ShowStatusBar="false"
        OnNeedDataSource="RadGrid1_NeedDataSource"
        OnItemDataBound="RadGrid1_ItemDataBound"
        OnItemCommand="RadGrid1_ItemCommand"
        OnGroupsChanging="RadGrid1_GroupsChanging"
        OnColumnCreated="RadGrid1_ColumnCreated"
        OnDataBound="RadGrid1_DataBound"
        OnSortCommand="RadGrid1_SortCommand"
        OnItemCreated="RadGrid1_ItemCreated"
        OnPreRender="RadGrid1_PreRender"
        HorizontalAlign="NotSet"
        Visible="false">
        <ClientSettings AllowColumnHide="true"
            AllowColumnsReorder="true"
            AllowDragToGroup="true"
            ReorderColumnsOnClient="true"
            AllowKeyboardNavigation="true"
            AllowRowsDragDrop="true"
            AllowAutoScrollOnDragDrop="false"
            EnablePostBackOnRowClick="false"
            EnableRowHoverStyle="true">
            <Resizing AllowColumnResize="true" EnableRealTimeResize="true" ResizeGridOnColumnResize="true" />
            <Selecting AllowRowSelect="true" />
            <Scrolling UseStaticHeaders="true" SaveScrollPosition="true" AllowScroll="true" />
            <ClientEvents OnRowContextMenu="RadGrid1_RowContextMenu"
                OnRowDropping="RadGrid1_RowDropping"
                OnActiveRowChanged="RadGrid1_ActiveRowChanged"
                OnRowSelected="RadGrid1_RowSelected"
                OnRowDblClick="RadGrid1_RowDblClick"
                OnKeyPress="RadGrid1_KeyPress"
                OnCommand="RadGrid1_Command"
                OnRowClick="rowClick"
                OnRowMouseOver="RowMouseOver"
                OnRowMouseOut="RowMouseOut"            
                OnMasterTableViewCreated="RadGrid1_MasterTableViewCreated" />
        </ClientSettings>
        <MasterTableView AllowMultiColumnSorting="false" DataKeyNames="ID,Unread,FolderPath" Width="100%"
            ClientDataKeyNames="ID,Unread,FolderPath" TableLayout="Fixed">
            <PagerStyle Mode="NextPrevNumericAndAdvanced" PageButtonCount="3" AlwaysVisible="true" />
        </MasterTableView>
     </telerik:RadGrid>


This is how I am getting the index from js:
function RadGrid1_RowSelected(sender, eventArgs)
{
    var mst = sender.get_masterTableView();
    var index = eventArgs.get_gridDataItem().get_element().rowIndex;
}

I would like to know if the behavior of the RadGrid has been changed since the older version, or I am doing something wrong here.

Thank you.



2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 May 2014, 05:59 AM
Hi Ali,

You can try the following code snippet to get index of a first selected row:

JS:
function RadGrid1_RowSelected(sender, eventArgs)
{
 var index = sender.get_masterTableView().get_selectedItems()[0]._itemIndexHierarchical;     
}

Thanks,
Princy
0
Ali
Top achievements
Rank 1
answered on 26 May 2014, 01:51 AM
Thank you Princy.
Using _itemIndexHierarchical solved the problem.


Regards.
Tags
Grid
Asked by
Ali
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ali
Top achievements
Rank 1
Share this question
or