How do I reset the scroller to position 0 on .Draw()

How do I reset the scroller to position 0 on .Draw()

wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

There are lots of tips and information on how to keep the current position of the scroller on a Draw() but I actually want it to return to the top of the Scroller. I could I suppose do the draw then jump to position 0 but that would require 2 ajax calls to the database.

I'm having a problem in IE7 that when the draw is done if the scroller was sat at record 5000 (server side paging) and after the draw there are 2000 records it isnt always resetting itself to the last record.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You probably don't want to return to the top on draw, otherwise you wouldn't ever be able to see anything other than the top page or two of data (since a draw is triggered on scroll!).

    I suspect the issue you are seeing isn't limited to IE7? The DataTables server-side processing protocol doesn't actually currently cope with smaller result sets being returned. What needs to happen is that the sever should have the ability to say to the client that the number of rows has been returned, and although you requested page y of data, you should actually display page z and here is that data.

    I need to update the server-side processing protocol and all my scripts to provide that ability. Sorry I don't have an immediate solution for you.

    Allan

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

    What would be the best (quickest) way to 'kill' the table so to speak and reload it as if it was a new one. As this would act as if the table had just been loaded solving the issue.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Probably the destroy option, or destroy().

    Allan

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

    Why does this not work

    Some Click function() {
    table.destroy();
    table= null;
    createTable();
    }

    createTable() being the function that creates the table.

    table being the 'global var' that holds the table being created.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Looks like it should from your description. I'd need a test page showing the issue be to able to understand why it isn't working I think.

    Allan

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

    I have emailed you over a test page.

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

    Hi Allen I have solved it. It was simple me being thick tired or who knows. I had the function defined in the wrong place.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Hi,

    Apologies for the delay in getting back to you on this. Thanks for the e-mails - good to hear you've got it working now!

    There is another option, which might be a little cleaner than destroying the table - that is to use the scrollToRow method and set it to 0. For example:

    $('#myTable').DataTable().scroller().scrollToRow(0);
    

    You would also want to call draw() to get the latest data from the server for that initial page.

    Regards,
    Allan

  • wjhumphreyswjhumphreys Posts: 52Questions: 9Answers: 5

    Ill give that one a try

This discussion has been closed.