How can I set the width of a column, on a table that is already initiated?

How can I set the width of a column, on a table that is already initiated?

TobiasNolimiTobiasNolimi Posts: 1Questions: 1Answers: 0

Hi all!

I want to set the width of my first column in my table, to make sure it is an exact width. For this support case here, I have just 100px as my example.

The table has already been inititiated, so it has to be set afterwards. The table has a fixedheader, and the first column is also fixed.

Below is the code that I use, and while it does change the sWidth property in the Settings, I can't get it to change the table at all. Any suggestions?

//Define my new width
let newWidth = 100;

//Set the width of the first column in the table settings
dataTableInstance.dataTableInstance.settings()[0].aoColumns[0].sWidth = newWidth + 'px';

//Redraw the table
dataTableInstance.columns().render();
dataTableInstance.columns.adjust().draw();

Answers

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    You can't, sorry. There is no public API that provides that ability in DataTables.

    What I would encorage you to do is put the DataTable in a div container and change the width of that container. When you change the width of the container, make sure you call columns.adjust() to tell DataTables about the change.

    Allan

Sign In or Register to comment.