.fixedColumns().relayout() not working

.fixedColumns().relayout() not working

tikhoninatikhonina Posts: 6Questions: 2Answers: 0

My table initialisation looks like this:
var table = $(tableSelector).DataTable({ order: [], "paging": false, "scrollX": 900, "scrollY": 550, scrollCollapse: true, buttons: true, fixedColumns: { leftColumns: 1 } });
It uses html-sourced data. When html data changes, I reitialize it with this code. Everything works fine except one thing: if the table appears to be smaller than screen in width, i see duplicated left column and other columns scattered on the width od the screen like this:

I'm using the example code from here (https://datatables.net/reference/api/fixedColumns().relayout()):
$.fn.dataTable .tables( { visible: true, api: true } ) .columns.adjust() .fixedColumns().relayout();
But it doesn't work. And also WebStorm tells methods adjust() and relayout() are unresolved.
I don't know, where is my mistake. Please, help:)

Answers

  • tikhoninatikhonina Posts: 6Questions: 2Answers: 0

    I left out the headers of the table, becase they represent db fields and my compony wouldn't be happy))

  • tikhoninatikhonina Posts: 6Questions: 2Answers: 0

    I found a solution: just set "scrollY" to 0. Is there some other way to do it?

  • ashish9342ashish9342 Posts: 2Questions: 0Answers: 0
    edited January 2018

    Facing same issue
    1. when the data is small table doesn't resize (fixed column width)
    tried api listed but din't work.

    $('#dataTable-' + tableID).html(_tableTemplate);
    $('#myDataTable-' + tableID).DataTable({
    scrollY: "300px",
    scrollX: true,
    scrollCollapse: true,
    paging: false,
    fixedColumns: { leftColumns: cols },
    ordering: false
    }).fixedColumns().relayout();

    Current output : https://imgur.com/MUdQsrZ

    Expected output : https://imgur.com/a/ctbjR

  • ashish9342ashish9342 Posts: 2Questions: 0Answers: 0
    edited January 2018

    Hey I gave a delay ..It works fine for me...

    setTimeout(function(){
    $.fn.dataTable.tables( { visible: true, api: true } )
    .columns.adjust()
    .fixedColumns().relayout();
    }, 300);

    Tried reaching you out for same but couldn't find you ..Search me as ashish9342 in google

This discussion has been closed.