API to programmatically read columns widths

API to programmatically read columns widths

NovidisNovidis Posts: 11Questions: 2Answers: 0

Are there any API to get colums widths afetr the datable has been rendered?

Replies

  • allanallan Posts: 63,687Questions: 1Answers: 10,500 Site admin

    Not via DataTables. You could use jQuery's $().width() method though.

    Allan

  • NovidisNovidis Posts: 11Questions: 2Answers: 0

    In our application we need to know the witdh of each column or to define it programmatically
    You can refer to this example: agrisophia.nubilo.it:52531/test_plugin
    No widths are returned by jQuery (please refer to the log in the console)
    at the same time the configuration
    "columnDefs": [{ "width": 100, "targets": "_all" }]
    seems not to be take in account

  • kthorngrenkthorngren Posts: 21,444Questions: 26Answers: 4,974

    This is your code to display the columns width:

                    var datatablecolumns = $('#View_Summary_Group_Info_Table_' + subcenter_index + ' tbody tr td');
                    $.each(datatablecolumns, function( index, datatablecolumn ) {
                      //datatablecolumn.width = 50;
                      console.log('column:'+index+' width:'+datatablecolumn.width);
                    });
    

    You aren't using jQuery to get the column widths. Try this:

    console.log('column:'+index+' width:'+ $(datatablecolumn).width());
    

    Kevin

  • NovidisNovidis Posts: 11Questions: 2Answers: 0

    Ok, thanks now we succesfully read the columns width and can align several table in the same page

This discussion has been closed.