Get row index of bottom most row

6 posts, 0 answers
  1. Jeremy Yoder
    Jeremy Yoder avatar
    131 posts
    Member since:
    Dec 2009

    Posted 23 Mar Link to this post

     

    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?

  2. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 28 Mar Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jeremy Yoder
    Jeremy Yoder avatar
    131 posts
    Member since:
    Dec 2009

    Posted 29 Mar in reply to Kostadin Link to this post

     

    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.

     

  5. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 01 Apr Link to this post

    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.
  6. Jeremy Yoder
    Jeremy Yoder avatar
    131 posts
    Member since:
    Dec 2009

    Posted 04 Apr in reply to Kostadin Link to this post

     

    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

  7. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 07 Apr Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017