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
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
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.
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
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
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