FixedColumn calculating incorrect column width with changing column.visible()

FixedColumn calculating incorrect column width with changing column.visible()

djkong7djkong7 Posts: 22Questions: 3Answers: 0

I have an example of this in: http://live.datatables.net/hisajofe/1/

If you use the dropdown on the top of the page to change which columns are visible, fixed columns will occasionally compute the incorrect column size. Changing from showing by the Position to showing All is the most repeatable change that will mess up for me. The strange part is that the total width of the visible fixed columns is always correct. Any ideas on why this is happening or what I can do to fix it?

Replies

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @djkong7 ,

    I added a call to columns().adjust() and that seems better here.

    Cheers,

    Colin

  • djkong7djkong7 Posts: 22Questions: 3Answers: 0

    Hey @colin ,

    This didn't appear to solve the issue at all for me. Any other ideas?

    Thanks,
    Dan

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Need to do a draw() on the table as well to allow the scrolling column alignment to update: http://live.datatables.net/hisajofe/4/edit

    Allan

  • djkong7djkong7 Posts: 22Questions: 3Answers: 0

    Ahhh. That's what I was missing. That works. Thank you!

  • djkong7djkong7 Posts: 22Questions: 3Answers: 0
    edited September 2019

    @allan, This solution does work, but I am using server side in my actual implementation and calling draw results in an unnecessary call to the server. Some of my search queries can take up to 20 seconds to return, so a call to the server to load the same data is problematic. I tired calling draw() with each of the 3 possible parameters with no luck. Is there a way to call draw() without a call to the server or a different way to get the column widths to correctly calculate?

    Because I'm now calling adjust on the columns, I figured it would be best to change the visibility with visibility([true/false], false) to get a little performance boost. Unfortunately, this is really messing with Fixed Columns and the fixed column column titles aren't changing. Example at http://live.datatables.net/hisajofe/13/ . Any thoughts on this issue?

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Call draw() with false as its only parameter: http://live.datatables.net/hisajofe/14/edit .

    Allan

  • djkong7djkong7 Posts: 22Questions: 3Answers: 0

    This did not solve either issue for me. I would love to create an example but I'm unsure how to create a server side example.

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @djkong7 ,

    This example here is using server-side processing - could you blend that in with your current example to demonstrate the issue?

    Cheers,

    Colin

  • djkong7djkong7 Posts: 22Questions: 3Answers: 0

    Hey @colin

    Here is a working example of this issue http://live.datatables.net/bareyifa/2/ . The processing indicator shows up and Chrome network monitor shows a request going out.

    Thank you,
    Dan

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi Dan,

    You are right - my apologies. I've given you dodgy information there.

    The key here is that we need to trigger DataTables scroll draw function - there isn't an external API for that other than the draw() method currently. But we could do a hacky little workaround in this case:

        table.columns.adjust();
        $.fn.dataTable.oApi._fnScrollDraw(table.settings()[0]);
    

    http://live.datatables.net/bareyifa/3/edit

    Allan

  • djkong7djkong7 Posts: 22Questions: 3Answers: 0

    @allan and @colin ,

    I wanted to say thank you both so much for taking the time out of your days to help! With the fixes you provided, I was able to get the tables to render correctly with no side effects. You two provide some of the best support I've experienced.

    Thank you again,
    Dan

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @djkong7 ,

    Thanks for the feedback, glad to know we're helping :)

    Cheers,

    Colin

This discussion has been closed.