From 1a9c11edf0a442d8b6ce9dcb2c53ab903396efd6 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Sat, 28 Sep 2019 14:00:18 +0530 Subject: [PATCH] fix: Render fluid layout if first row doesnt exist --- src/style.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/style.js b/src/style.js index 76bc761..0dfae46 100644 --- a/src/style.js +++ b/src/style.js @@ -251,7 +251,16 @@ export default class Style { if (this.options.layout !== 'fluid') return; const wrapperWidth = $.style(this.instance.datatableWrapper, 'width'); - const firstRowWidth = $.style($('.dt-row', this.bodyScrollable), 'width'); + let firstRow = $('.dt-row', this.bodyScrollable); + let firstRowWidth = wrapperWidth; + if (!firstRow) { + let headerRow = $('.dt-row', this.instance.header); + let cellWidths = Array.from(headerRow.children) + .map(cell => cell.offsetWidth); + firstRowWidth = cellWidths.reduce((sum, a) => sum + a, 0); + } else { + firstRowWidth = $.style(firstRow, 'width'); + } const resizableColumns = this.datamanager.getColumns().filter(col => col.resizable); const deltaWidth = (wrapperWidth - firstRowWidth) / resizableColumns.length;