Wrong column size when I use colspan in first row - Second post

Wrong column size when I use colspan in first row - Second post

proteos_engineeringproteos_engineering Posts: 5Questions: 0Answers: 0

Hi guys, I found the solution related to "resizing incorrect columns" of the table which has the first row with "colspan" attribute. It also often comes with the "RowGroup" plugin.
While waiting for the best solution proposed by Allan, I write my solution:

In datatables.js about at row 5012:

// 2. Correct colgroup > col values if needed
// It is possible that the cell sizes are smaller than the content, so we need to
// correct colgroup>col for such cases. This can happen if the auto width detection
// uses a cell which has a longer string, but isn't the widest! For example
// "Chief Executive Officer (CEO)" is the longest string in the demo, but
// "Systems Administrator" is actually the widest string since it doesn't collapse.
if (settings.aiDisplay.length) {
// Get the column sizes from the first row in the table
// MODIFY HERE
var colSizes = (table.find('tbody tr:not(.group)').length > 0 ? table.find('tbody tr:not(.group)') : table.find('tbody tr')).eq(0).find('th, td').map(function () {
return $(this).outerWidth();
});

// Check against what the colgroup > col is set to and correct if needed
$('col', settings.colgroup).each(function (i) {
    var colWidth = this.style.width.replace('px', '');

    if (colWidth !== colSizes[i]) {
        this.style.width = colSizes[i] + 'px';
    }
});

}

Norberto

Replies

  • allanallan Posts: 61,930Questions: 1Answers: 10,153 Site admin

    Hi Norberto,

    Very cool - thanks for posting this. It might indeed require a workaround along these lines in the code. I'd like to get some feedback from the browser makers on their table width algorithms.

    Allan

Sign In or Register to comment.