What is the difference between columns.adjust() vs columns.adjust().draw() ?

What is the difference between columns.adjust() vs columns.adjust().draw() ?

ashwinrajagopalashwinrajagopal Posts: 4Questions: 1Answers: 0

When I am changing a dropdown value within a DataTable then it brings the user to the top of the Table (titles ) .
After analyzing the code I found that
" table.columns.adjust().draw(false) "
is being used on change of the dropdown to adjust column width of entire table to correctly accommodate new custom column response .

When I changed the code from " table.columns.adjust().draw(false) " to " table.columns.adjust()" it is not bringing the user to the top of the Table which resolves my issue . But I want to know the diff between

" table.columns.adjust().draw(false) " & " table.columns.adjust()" . Thanks in advance .

Answers

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @ashwinrajagopal ,

    Calling columns.adjust() won't redraw the display - so the change in widths won't happen until the next draw (such as when the ordering is changed or a different page selected). The draw() does the refresh.

    Cheers,

    Colin

  • ashwinrajagopalashwinrajagopal Posts: 4Questions: 1Answers: 0
    edited April 2019

    Hi @colin ,

    Thank you very much for the information . But when I am changing a value of dropdown in the table , it fires an event which does some data fetch so to adjust the newly populated data I am using columns.adjust().draw() but it will scroll up to the table header making the user confusing as the page is being scrolled up rather than staying in the specific row . How can we fix this issue ? Please suggest any solution if you could .

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @ashwinrajagopal ,

    Try draw('page'), that may help. If not, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • ashwinrajagopalashwinrajagopal Posts: 4Questions: 1Answers: 0

    @colin Thank you Colin . But still I am facing the issue .

    Actual issue is when I am trying to call adjust().draw(false) or adjust.draw('page') on an drop down change event which is placed towards the bottom of the DataTable
    ( where the scroll is down ) , will take the user to the title of the DataTable (scrolling up ) . I tried creating a test case as per the link
    live.datatables.net/bidarezi/2/edit

    you provided but it is not getting reproduced ) .

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @ashwinrajagopal ,

    Thanks for the demo, but as you say, it's not reproducing the issue. Without seeing it, it's hard to diagnose and make any further suggestions.

    Cheers,

    Colin

  • ashwinrajagopalashwinrajagopal Posts: 4Questions: 1Answers: 0

    Hi @colin

    I have found one thread in stack overflow related to this but the solutions provided are not working for me . Any suggestion from your side , would be a great help . Thank you

    https://stackoverflow.com/questions/27663743/how-to-maintain-jquery-datatables-scroll-position-after-draw

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    Hi @ashwinrajagopal ,

    As I said in my last two comments, the best way to progress this is to provide a test case - without it, we're shooting in the dark.

    Cheers,

    Colin

This discussion has been closed.