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

Get row index of bottom most row

5 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeremy Yoder
Top achievements
Rank 1
Jeremy Yoder asked on 23 Mar 2016, 02:31 PM

 

This seems easy, but I can't figure it out. No matter what rows have been added, or how it's been ordered, I want the index of the bottom most row in the grid via client side javascript. There's no paging. It doesn't appear that get_dataItems() always have [0] as the top and [length - 1] as the bottom, so how can I get the bottom most row's index?

5 Answers, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 28 Mar 2016, 07:07 AM
Hello Jeremy,

In case you need the index of the last row then you can use get_dataItems().length - 1. If you need to get some cell value from the last row then you can use the get_cell method and pass the column UniqueName. For your convenience, I prepared a small sample and attached it to this thread.

Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Jeremy Yoder
Top achievements
Rank 1
answered on 29 Mar 2016, 02:16 PM

 

Thanks for the example. I modified it a bit to mimic mine, by adding EditMode="Batch" and InsertItemDisplay="Bottom"

Run it again, click "Add new record" at least once (optionally adding data) and click your "Get last rows" button. You'll still get the last row prior to the newly added rows. How can I get the index of the bottom most row, regardless if it's been newly added or not?

get_dataItems().length - 1 does increase with each additional row, but it always points to the same row.

 

0
Kostadin
Telerik team
answered on 01 Apr 2016, 07:16 AM
Hi Jeremy,

When using batch editing and you add new records those items have a negative index and they are added at the beginning of the dataItems collection. So basically if you want to access the last new row you can get the first object from the dataItems array.
masterTableView.get_dataItems()[0]

Keep in mind when you save the changes this rows will be added to the correct position in the array.

Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Jeremy Yoder
Top achievements
Rank 1
answered on 04 Apr 2016, 03:46 PM

 

But I don't know if there have been new records added or not, so get_dataItems[0] may works sometimes but not others.

Anyway, I got this code check from elsewhere, so I'm hoping it does the trick. So far it seems to work, and maybe will help others, though it requires me to loop through all records from get_dataItems. Let me know if you see anything wrong with it...

 

if (!row.nextSibling || row.nextSibling.className.indexOf("rgNoRecords") !== -1) {
    // this is the last row

0
Kostadin
Telerik team
answered on 07 Apr 2016, 11:47 AM
Hello Jeremy,

You can use the provided code if it works properly on your side. Another possible solution is to check whether the row id contains a minus sign. Note that each new rows have a negative index so you can check for any in the row id.

Regards,
Kostadin
Telerik
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
Jeremy Yoder
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Jeremy Yoder
Top achievements
Rank 1
Share this question
or