From 3930a76e0f3bba8a08fa3540ec44c42f8af2aa10 Mon Sep 17 00:00:00 2001 From: emertechie Date: Sun, 20 Nov 2011 12:15:16 +0000 Subject: [PATCH] Added support for autoWidth column option (only works if forceFitColumns enabled for grid) --- slick.grid.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/slick.grid.js b/slick.grid.js index 253027f45..f7c9b2ce3 100644 --- a/slick.grid.js +++ b/slick.grid.js @@ -805,19 +805,31 @@ if (typeof Slick === "undefined") { shrinkLeeway = 0, availWidth = (options.autoHeight ? viewportW : viewportW - scrollbarDimensions.width), // with AutoHeight, we do not need to accomodate the vertical scroll bar total = 0, - existingTotal = 0; + existingTotal = 0, + autoWidthColIndex; for (i = 0; i < columns.length; i++) { c = columns[i]; widths.push(c.width); - existingTotal += c.width; shrinkLeeway += c.width - Math.max(c.minWidth || 0, absoluteColumnMinWidth); + if (c.autoWidth){ + if (autoWidthColIndex) throw "Only 1 column can use autoWidth"; + autoWidthColIndex = i; + } + else { + existingTotal += c.width; + } } - total = existingTotal; + total = existingTotal; invalidateAllRows(); + if (autoWidthColIndex) { + widths[autoWidthColIndex] = Math.max(columns[autoWidthColIndex].minWidth || 0, Math.floor(availWidth - total)); + total = availWidth; + } + // shrink while (total > availWidth) { if (!shrinkLeeway) { return; }