1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-17 22:06:41 +02:00

Merge pull request #581 from koalyptus/auto-min-width

ensure table layout is fixed when cols widths are defined
This commit is contained in:
koalyptus 2018-04-02 20:35:17 +10:00 committed by GitHub
commit e09d30c2cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 56 additions and 33 deletions

4
dist/starter.html vendored
View file

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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

38
package-lock.json generated
View file

@ -1,6 +1,6 @@
{
"name": "tablefilter",
"version": "0.6.22",
"version": "0.6.23",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -1936,7 +1936,7 @@
"circular-json": {
"version": "0.3.3",
"resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz",
"integrity": "sha1-gVyZ6oT2gJUp0vRXkb34JxE1LWY=",
"integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==",
"dev": true
},
"class-utils": {
@ -2802,7 +2802,7 @@
"doctrine": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
"integrity": "sha1-XNAfwQFiG0LEzX9dGmYkNxbT850=",
"integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==",
"dev": true,
"requires": {
"esutils": "2.0.2"
@ -3221,9 +3221,9 @@
"dev": true
},
"eslint": {
"version": "4.19.0",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.0.tgz",
"integrity": "sha512-r83L5CuqaocDvfwdojbz68b6tCUk8KJkqfppO+gmSAQqYCzTr0bCSMu6A6yFCLKG65j5eKcKUw4Cw4Yl4gfWkg==",
"version": "4.19.1",
"resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz",
"integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==",
"dev": true,
"requires": {
"ajv": "5.5.2",
@ -3241,7 +3241,7 @@
"file-entry-cache": "2.0.0",
"functional-red-black-tree": "1.0.1",
"glob": "7.1.2",
"globals": "11.3.0",
"globals": "11.4.0",
"ignore": "3.3.7",
"imurmurhash": "0.1.4",
"inquirer": "3.3.0",
@ -3257,7 +3257,7 @@
"path-is-inside": "1.0.2",
"pluralize": "7.0.0",
"progress": "2.0.0",
"regexpp": "1.0.1",
"regexpp": "1.1.0",
"require-uncached": "1.0.3",
"semver": "5.5.0",
"strip-ansi": "4.0.0",
@ -3307,16 +3307,16 @@
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha1-W7WgZyYotkFJVmuhaBnmFRjGcmE=",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"globals": {
"version": "11.3.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.3.0.tgz",
"integrity": "sha1-4E/be5eW2K2snI9kwUg3sjEzeLA=",
"version": "11.4.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-11.4.0.tgz",
"integrity": "sha512-Dyzmifil8n/TmSqYDEXbm+C8yitzJQqQIlJQLNRMwa+BOUJpRC19pyVeN12JAjt61xonvXjtff+hJruTRXn5HA==",
"dev": true
},
"strip-ansi": {
@ -6228,7 +6228,7 @@
"ignore": {
"version": "3.3.7",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.7.tgz",
"integrity": "sha1-YSKJv7PCIOGGpYEYYY1b6MG6sCE=",
"integrity": "sha512-YGG3ejvBNHRqu0559EOxxNFihD0AjpvHlC/pdGKd3X3ofe+CoJkYazwNJYTNebqpPKN+VVQbh4ZFn1DivMNuHA==",
"dev": true
},
"import-local": {
@ -6668,7 +6668,7 @@
"is-resolvable": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-resolvable/-/is-resolvable-1.1.0.tgz",
"integrity": "sha1-+xj4fOH+uSUWnJpAfBkxijIG7Yg=",
"integrity": "sha512-qgDYXFSR5WvEfuS5dMj6oTMEbrrSaM0CrFk2Yiq/gXnBvD9pMa2jGXxyhGLfvhZpuMZe18CJpFxAt3CRs42NMg==",
"dev": true
},
"is-retry-allowed": {
@ -8920,7 +8920,7 @@
"pluralize": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz",
"integrity": "sha1-KYuJ34uTsCIdv0Ia0rGx6iP8Z3c=",
"integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==",
"dev": true
},
"pop-arrayify": {
@ -9485,9 +9485,9 @@
"dev": true
},
"regexpp": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.0.1.tgz",
"integrity": "sha512-8Ph721maXiOYSLtaDGKVmDn5wdsNaF6Px85qFNeMPQq0r8K5Y10tgP6YuR65Ws35n4DvzFcCxEnRNBIXQunzLw==",
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz",
"integrity": "sha512-LOPw8FpgdQF9etWMaAfG/WRthIdXJGYp4mJ2Jgn/2lpkbod9jPn0t9UqN7AxBOKNfzRbYyVfgc7Vk4t/MpnXgw==",
"dev": true
},
"regexpu-core": {
@ -10013,7 +10013,7 @@
"slice-ansi": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-1.0.0.tgz",
"integrity": "sha1-BE8aSdiEL/MHqta1Be0Xi9lQE00=",
"integrity": "sha512-POqxBK6Lb3q6s047D/XsDVNPnF9Dl8JSaqe9h9lURl0OdNqy/ujDrOiIHtsqXMGbWWTIomRzAMaTyawAU//Reg==",
"dev": true,
"requires": {
"is-fullwidth-code-point": "2.0.0"

View file

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

View file

@ -1040,6 +1040,9 @@ export class TableFilter {
if (this.responsive) {
addClass(this.dom(), this.prfxResponsive);
}
if (this.colWidths.length > 0) {
this.setFixedLayout();
}
}
/* Load extensions */
@ -2509,17 +2512,35 @@ export class TableFilter {
}
/**
* Set them columns' widths as per configuration
* @param {Element} tbl DOM element
* Make passed or default working table element width fixed
* @param {TableElement} tbl optional table DOM element
*/
setColWidths(tbl) {
setFixedLayout(tbl = this.dom()) {
let colWidths = this.colWidths;
let tableWidth = tbl.clientWidth;
if (colWidths.length > 0) {
tableWidth = colWidths
.reduce((x, y) =>
parseInt((x || 0), 10) + parseInt((y || 0), 10)
);
}
tbl.style.width = `${tableWidth}px`;
tbl.style.tableLayout = 'fixed';
}
/**
* Set passed or default working table columns' widths with configuration
* values
* @param {TableElement} tbl optional table DOM element
*/
setColWidths(tbl = this.dom()) {
let colWidths = this.colWidths;
if (colWidths.length === 0) {
return;
}
tbl = tbl || this.dom();
let colTags = tag(tbl, 'col');
let tblHasColTag = colTags.length > 0;
let frag = !tblHasColTag ? doc.createDocumentFragment() : null;

View file

@ -26,6 +26,7 @@ table.TF
margin 0
padding $padding
border-bottom 1px solid $td-border-color
text-overflow ellipsis
// responsiveness
&.resp

View file

@ -48,8 +48,8 @@
},
col_widths: [
'150px', '100px', '100px',
'70px', '70px', '70px',
'70px', '60px', '60px'
'90px', '90px', '90px',
'90px', '70px', '70px'
],
extensions:[{ name: 'sort' }]
};

View file

@ -13,7 +13,8 @@
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, '', 'Table width not set');
deepEqual(tf.dom().style.width, '545px', 'Table width set');
deepEqual(tf.dom().style.tableLayout, 'fixed', 'Table layout fixed');
});
test('Grid layout column widths', function() {