introduce default column width

This commit is contained in:
koalyptus 2018-04-07 10:45:33 +10:00
parent 39bbe6a19a
commit 025717f61c
7 changed files with 17 additions and 10 deletions

View File

@ -13,7 +13,7 @@
"array-bracket-spacing": 2,
"keyword-spacing": ["error", { "after": true, "before": true }],
"max-depth": [2, 7],
"max-statements": [2, 130],
"max-statements": [2, 131],
"complexity": [2, 41],
"no-unused-vars": 2,
"no-eval": 2,

4
dist/starter.html vendored
View File

@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>tablefilter v0.6.23 - Starter</title>
<title>tablefilter v0.6.24 - Starter</title>
</head>
<body>
<h1>tablefilter v0.6.23</h1>
<h1>tablefilter v0.6.24</h1>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "tablefilter",
"version": "0.6.23",
"version": "0.6.24",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {

View File

@ -268,6 +268,11 @@ export class TableFilter {
*/
this.colWidths = defaultsArr(f.col_widths, []);
/**
* Default column width when column widths are defined
*/
this.defaultColWidth = defaultsNb(f.default_col_width, 100);
/**
* Css class for a filter element
* @type {String}
@ -2520,9 +2525,11 @@ export class TableFilter {
let tableWidth = tbl.clientWidth;
if (colWidths.length > 0) {
let defaultWidth = this.defaultColWidth;
tableWidth = colWidths
.reduce((x, y) =>
parseInt((x || 0), 10) + parseInt((y || 0), 10)
parseInt((x || defaultWidth), 10) +
parseInt((y || defaultWidth), 10)
);
}

View File

@ -13,7 +13,7 @@
deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
deepEqual(cols[1].style.width, '100px', 'Expected column width');
deepEqual(cols[4].style.width, '', 'Expected column width');
deepEqual(tf.dom().style.width, '545px', 'Table width set');
deepEqual(tf.dom().style.width, '645px', 'Table width set');
deepEqual(tf.dom().style.tableLayout, 'fixed', 'Table layout fixed');
});
@ -22,14 +22,14 @@
tf = null;
tf = new TableFilter('demo', {
base_path: '../dist/tablefilter/',
col_widths: ['150px', '100px', '175px', '120px', '200px'],
col_widths: ['150px', '100px', '175px', '120px', null],
grid_layout: true
});
tf.init();
var gridLayout = tf.feature('gridLayout');
var cols = gridLayout.headTbl.getElementsByTagName('col');
deepEqual(cols[0].style.width, '150px', 'Expected column width');
deepEqual(cols[4].style.width, '200px', 'Expected column width');
deepEqual(cols[3].style.width, '120px', 'Expected column width');
deepEqual(
tf.dom().style.width === gridLayout.headTbl.style.width,
true,