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

get_itemIndexHierarchical returns incorrect index

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael Pullella
Top achievements
Rank 1
Michael Pullella asked on 14 Jun 2010, 04:36 PM
Hello

I am attempting to access the index of a row selected in a radGrid using itemIndexHierarchical, however I am getting an incorrect index in certain cases.

I am binding my data on the client using set_dataSource(json) and dataBind().  If there are no rows when the grid is first populated, then I add one (or several) by adding an item to my json, then doing set_dataSource and dataBind(), then call itemIndexHierarchical(), the index that gets returned is 1 higher than it should be.

Any workaround to this (other than counting the number of items in the grid before I do anything, if there are 0, then subtract 1 from the value I get back from itemIndexHierarchical())?

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 17 Jun 2010, 09:36 AM
Hello Michael,

I am afraid I cannot replicate described behavior. Bellow is the code that I've used for testing:
/markup/
01.<telerik:RadGrid runat="server" ID="RadGrid1" AutoGenerateColumns="false">
02.        <MasterTableView>
03.            <Columns>
04.             <telerik:GridBoundColumn DataField="InvoiceDate" DataFormatString="{0:d}" DataType="System.DateTime">
05.                </telerik:GridBoundColumn>
06.</Columns>
07.        </MasterTableView>
08.        <ClientSettings>
09.            <ClientEvents OnCommand="function(){}" />
10.        </ClientSettings>
11.    </telerik:RadGrid>
12.  
13.<input type="button" onclick="rebind()" value="Add Item"/>

/script/
01.<script type="text/javascript">        
02.        function pageLoad()
03.        {
04.         var mtv = $find("RadGrid1").get_masterTableView();
05.         mtv.set_dataSource([]);
06.         mtv.dataBind();
07.        }
08.        function rebind()
09.        {
10.            var mtv = $find("RadGrid1").get_masterTableView();
11.            mtv.set_dataSource([{ InvoiceDate: new Date()}]);
12.            mtv.dataBind();            
13.            alert(mtv.get_dataItems()[0]._itemIndexHierarchical)
14.        }
15.    </script>


Best wishes,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Michael Pullella
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or