What is the correct way to use scrollToRow()

What is the correct way to use scrollToRow()

BeanlessSoupBeanlessSoup Posts: 1Questions: 1Answers: 0

I have a datatable with a few hundred rows. I want to be able to jump to a specific row based on various user inputs. I am getting weird results though. I assume if I want to jump to Row 20 I would enter something like:

                var tabResGrid = $('#tblResGrid').DataTable();
                tabResGrid.scroller().scrollToRow(20);

Doing so however the top row shown is 24. If I put in 40 the top row might be 49. 100 and it will show me 108. It seems to always be approximately correct but off by a number less than 12 no matter how large a number I go.

To workaround this temporarily I am subtracting 12 from the row number I really want to jump to (then it usually shows up somewhere close to where it needs to be). My workaround seems rather "hackish" and I wonder if there is a better solution- or some sort of explanation to what could be going on.

Answers

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49

    I handled this by using http://demos.flesler.com/jquery/scrollTo/ plugin and following code.

    $dataContainer = HTML div containing your DataTable
    $rowItem = HTML tr within table
    $('.dataTables_scrollBody', $dataContainer).scrollTo($rowItem, 1000);
    
  • allanallan Posts: 63,794Questions: 1Answers: 10,513 Site admin

    Can you link to the page showing the issue so I can help to debug it please? Also, I would suggest using row().scrollTo() since it provides additional selector options.

    Allan

This discussion has been closed.