diff --git a/dist/frappe-datatable.cjs.js b/dist/frappe-datatable.cjs.js index df8d806..21c9307 100644 --- a/dist/frappe-datatable.cjs.js +++ b/dist/frappe-datatable.cjs.js @@ -187,6 +187,27 @@ $.scrollTop = function scrollTop(element, pixels) { }); }; +$.scrollbarWidth = function scrollbarWidth() { + // Create the measurement node + const scrollDiv = document.createElement('div'); + $.style(scrollDiv, { + width: '100px', + height: '100px', + overflow: 'scroll', + position: 'absolute', + top: '-9999px' + }); + document.body.appendChild(scrollDiv); + + // Get the scrollbar width + const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + + // Delete the DIV + document.body.removeChild(scrollDiv); + + return scrollbarWidth; +}; + /** * Checks if `value` is the * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) @@ -723,20 +744,6 @@ function makeDataAttributeString(props) { .trim(); } -function getDefault(a, b) { - return a !== undefined ? a : b; -} - - - - - - - - - - - function copyTextToClipboard(text) { // https://stackoverflow.com/a/30810322/5353542 var textArea = document.createElement('textarea'); @@ -800,19 +807,25 @@ let throttle$1 = throttle_1; let debounce$2 = debounce_1; -function promisify(fn, context = null) { +function nextTick(fn, context = null) { return (...args) => { return new Promise(resolve => { - setTimeout(() => { + const execute = () => { const out = fn.apply(context, args); resolve(out); - }, 0); + }; + + if (window.setImmediate) { + setImmediate(execute); + } else if (window.requestAnimationFrame) { + requestAnimationFrame(execute); + } else { + setTimeout(execute); + } }); }; } - - function linkProperties(target, source, properties) { const props = properties.reduce((acc, prop) => { acc[prop] = { @@ -847,10 +860,10 @@ function ensureArray(val) { class DataManager { constructor(options) { this.options = options; - this.sortRows = promisify(this.sortRows, this); - this.switchColumn = promisify(this.switchColumn, this); - this.removeColumn = promisify(this.removeColumn, this); - this.filterRows = promisify(this.filterRows, this); + this.sortRows = nextTick(this.sortRows, this); + this.switchColumn = nextTick(this.switchColumn, this); + this.removeColumn = nextTick(this.removeColumn, this); + this.filterRows = nextTick(this.filterRows, this); } init(data, columns) { @@ -1345,6 +1358,12 @@ class DataManager { getColumn(colIndex) { colIndex = +colIndex; + + if (colIndex < 0) { + // negative indexes + colIndex = this.columns.length + colIndex; + } + return this.columns.find(col => col.colIndex === colIndex); } @@ -1665,9 +1684,8 @@ class ColumnManager { const $cell = span.closest('.data-table-cell'); let { colIndex, - sortOrder + sortOrder = 'none' } = $.data($cell); - sortOrder = getDefault(sortOrder, 'none'); const col = this.getColumn(colIndex); if (col && col.sortable === false) { @@ -1807,18 +1825,16 @@ class ColumnManager { return this.datamanager.getColumns(); } - setColumnWidth(colIndex) { + setColumnWidth(colIndex, width) { colIndex = +colIndex; this._columnWidthMap = this._columnWidthMap || []; - const { - width - } = this.getColumn(colIndex); + let columnWidth = width || this.getColumn(colIndex).width; let index = this._columnWidthMap[colIndex]; const selector = `[data-col-index="${colIndex}"] .content, [data-col-index="${colIndex}"] .edit-cell`; const styles = { - width: width + 'px' + width: columnWidth + 'px' }; index = this.style.setStyle(selector, styles, index); @@ -2621,7 +2637,7 @@ class RowManager { ]); this.bindEvents(); - this.refreshRows = promisify(this.refreshRows, this); + this.refreshRows = nextTick(this.refreshRows, this); } get datamanager() { @@ -2896,7 +2912,7 @@ class BodyRenderer { this.cellmanager = instance.cellmanager; this.bodyScrollable = instance.bodyScrollable; this.log = instance.log; - this.appendRemainingData = promisify(this.appendRemainingData, this); + this.appendRemainingData = nextTick(this.appendRemainingData, this); } render() { @@ -3017,6 +3033,7 @@ class Style { $.on(window, 'resize', throttle$1(() => { this.distributeRemainingWidth(); this.refreshColumnWidth(); + this.compensateScrollbarWidth(); this.setBodyStyle(); }, 300)); } @@ -3058,9 +3075,10 @@ class Style { this.setupMinWidth(); this.setupNaturalColumnWidth(); this.setupColumnWidth(); - this.distributeRemainingWidth(); this.setColumnStyle(); + this.compensateScrollbarWidth(); + this.setDefaultCellHeight(); this.setBodyStyle(); } @@ -3173,6 +3191,13 @@ class Style { } } + compensateScrollbarWidth() { + const scrollbarWidth = $.scrollbarWidth(); + const lastCol = this.datamanager.getColumn(-1); + const width = lastCol.width - scrollbarWidth; + this.columnmanager.setColumnWidth(lastCol.colIndex, width); + } + distributeRemainingWidth() { if (this.options.layout !== 'fluid') return; @@ -3580,7 +3605,7 @@ var name = "frappe-datatable"; var version = "0.0.2"; var description = "A modern datatable library for the web"; var main = "dist/frappe-datatable.cjs.js"; -var scripts = {"start":"npm run dev","build":"rollup -c","dev":"rollup -c -w","test":"mocha --compilers js:babel-core/register --colors ./test/*.spec.js","test:watch":"mocha --compilers js:babel-core/register --colors -w ./test/*.spec.js"}; +var scripts = {"start":"yarn run dev","build":"rollup -c","dev":"rollup -c -w","test":"mocha --compilers js:babel-core/register --colors ./test/*.spec.js","test:watch":"mocha --compilers js:babel-core/register --colors -w ./test/*.spec.js"}; var devDependencies = {"chai":"3.5.0","cssnano":"^3.10.0","deepmerge":"^2.0.1","eslint":"3.19.0","eslint-loader":"1.7.1","mocha":"3.3.0","postcss-cssnext":"^3.1.0","postcss-nested":"^3.0.0","precss":"^3.1.0","rollup-plugin-commonjs":"^8.3.0","rollup-plugin-json":"^2.3.0","rollup-plugin-node-resolve":"^3.0.3","rollup-plugin-postcss":"^1.2.8","rollup-plugin-uglify":"^3.0.0"}; var repository = {"type":"git","url":"https://github.com/frappe/datatable.git"}; var keywords = ["datatable","data","grid","table"]; diff --git a/dist/frappe-datatable.js b/dist/frappe-datatable.js index 682733d..85d028b 100644 --- a/dist/frappe-datatable.js +++ b/dist/frappe-datatable.js @@ -186,6 +186,27 @@ $.scrollTop = function scrollTop(element, pixels) { }); }; +$.scrollbarWidth = function scrollbarWidth() { + // Create the measurement node + const scrollDiv = document.createElement('div'); + $.style(scrollDiv, { + width: '100px', + height: '100px', + overflow: 'scroll', + position: 'absolute', + top: '-9999px' + }); + document.body.appendChild(scrollDiv); + + // Get the scrollbar width + const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + + // Delete the DIV + document.body.removeChild(scrollDiv); + + return scrollbarWidth; +}; + /** * Checks if `value` is the * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) @@ -722,20 +743,6 @@ function makeDataAttributeString(props) { .trim(); } -function getDefault(a, b) { - return a !== undefined ? a : b; -} - - - - - - - - - - - function copyTextToClipboard(text) { // https://stackoverflow.com/a/30810322/5353542 var textArea = document.createElement('textarea'); @@ -799,19 +806,25 @@ let throttle$1 = throttle_1; let debounce$2 = debounce_1; -function promisify(fn, context = null) { +function nextTick(fn, context = null) { return (...args) => { return new Promise(resolve => { - setTimeout(() => { + const execute = () => { const out = fn.apply(context, args); resolve(out); - }, 0); + }; + + if (window.setImmediate) { + setImmediate(execute); + } else if (window.requestAnimationFrame) { + requestAnimationFrame(execute); + } else { + setTimeout(execute); + } }); }; } - - function linkProperties(target, source, properties) { const props = properties.reduce((acc, prop) => { acc[prop] = { @@ -846,10 +859,10 @@ function ensureArray(val) { class DataManager { constructor(options) { this.options = options; - this.sortRows = promisify(this.sortRows, this); - this.switchColumn = promisify(this.switchColumn, this); - this.removeColumn = promisify(this.removeColumn, this); - this.filterRows = promisify(this.filterRows, this); + this.sortRows = nextTick(this.sortRows, this); + this.switchColumn = nextTick(this.switchColumn, this); + this.removeColumn = nextTick(this.removeColumn, this); + this.filterRows = nextTick(this.filterRows, this); } init(data, columns) { @@ -1344,6 +1357,12 @@ class DataManager { getColumn(colIndex) { colIndex = +colIndex; + + if (colIndex < 0) { + // negative indexes + colIndex = this.columns.length + colIndex; + } + return this.columns.find(col => col.colIndex === colIndex); } @@ -1664,9 +1683,8 @@ class ColumnManager { const $cell = span.closest('.data-table-cell'); let { colIndex, - sortOrder + sortOrder = 'none' } = $.data($cell); - sortOrder = getDefault(sortOrder, 'none'); const col = this.getColumn(colIndex); if (col && col.sortable === false) { @@ -1806,18 +1824,16 @@ class ColumnManager { return this.datamanager.getColumns(); } - setColumnWidth(colIndex) { + setColumnWidth(colIndex, width) { colIndex = +colIndex; this._columnWidthMap = this._columnWidthMap || []; - const { - width - } = this.getColumn(colIndex); + let columnWidth = width || this.getColumn(colIndex).width; let index = this._columnWidthMap[colIndex]; const selector = `[data-col-index="${colIndex}"] .content, [data-col-index="${colIndex}"] .edit-cell`; const styles = { - width: width + 'px' + width: columnWidth + 'px' }; index = this.style.setStyle(selector, styles, index); @@ -2620,7 +2636,7 @@ class RowManager { ]); this.bindEvents(); - this.refreshRows = promisify(this.refreshRows, this); + this.refreshRows = nextTick(this.refreshRows, this); } get datamanager() { @@ -2895,7 +2911,7 @@ class BodyRenderer { this.cellmanager = instance.cellmanager; this.bodyScrollable = instance.bodyScrollable; this.log = instance.log; - this.appendRemainingData = promisify(this.appendRemainingData, this); + this.appendRemainingData = nextTick(this.appendRemainingData, this); } render() { @@ -3016,6 +3032,7 @@ class Style { $.on(window, 'resize', throttle$1(() => { this.distributeRemainingWidth(); this.refreshColumnWidth(); + this.compensateScrollbarWidth(); this.setBodyStyle(); }, 300)); } @@ -3057,9 +3074,10 @@ class Style { this.setupMinWidth(); this.setupNaturalColumnWidth(); this.setupColumnWidth(); - this.distributeRemainingWidth(); this.setColumnStyle(); + this.compensateScrollbarWidth(); + this.setDefaultCellHeight(); this.setBodyStyle(); } @@ -3172,6 +3190,13 @@ class Style { } } + compensateScrollbarWidth() { + const scrollbarWidth = $.scrollbarWidth(); + const lastCol = this.datamanager.getColumn(-1); + const width = lastCol.width - scrollbarWidth; + this.columnmanager.setColumnWidth(lastCol.colIndex, width); + } + distributeRemainingWidth() { if (this.options.layout !== 'fluid') return; @@ -3579,7 +3604,7 @@ var name = "frappe-datatable"; var version = "0.0.2"; var description = "A modern datatable library for the web"; var main = "dist/frappe-datatable.cjs.js"; -var scripts = {"start":"npm run dev","build":"rollup -c","dev":"rollup -c -w","test":"mocha --compilers js:babel-core/register --colors ./test/*.spec.js","test:watch":"mocha --compilers js:babel-core/register --colors -w ./test/*.spec.js"}; +var scripts = {"start":"yarn run dev","build":"rollup -c","dev":"rollup -c -w","test":"mocha --compilers js:babel-core/register --colors ./test/*.spec.js","test:watch":"mocha --compilers js:babel-core/register --colors -w ./test/*.spec.js"}; var devDependencies = {"chai":"3.5.0","cssnano":"^3.10.0","deepmerge":"^2.0.1","eslint":"3.19.0","eslint-loader":"1.7.1","mocha":"3.3.0","postcss-cssnext":"^3.1.0","postcss-nested":"^3.0.0","precss":"^3.1.0","rollup-plugin-commonjs":"^8.3.0","rollup-plugin-json":"^2.3.0","rollup-plugin-node-resolve":"^3.0.3","rollup-plugin-postcss":"^1.2.8","rollup-plugin-uglify":"^3.0.0"}; var repository = {"type":"git","url":"https://github.com/frappe/datatable.git"}; var keywords = ["datatable","data","grid","table"]; diff --git a/docs/assets/frappe-datatable.js b/docs/assets/frappe-datatable.js index 682733d..85d028b 100644 --- a/docs/assets/frappe-datatable.js +++ b/docs/assets/frappe-datatable.js @@ -186,6 +186,27 @@ $.scrollTop = function scrollTop(element, pixels) { }); }; +$.scrollbarWidth = function scrollbarWidth() { + // Create the measurement node + const scrollDiv = document.createElement('div'); + $.style(scrollDiv, { + width: '100px', + height: '100px', + overflow: 'scroll', + position: 'absolute', + top: '-9999px' + }); + document.body.appendChild(scrollDiv); + + // Get the scrollbar width + const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + + // Delete the DIV + document.body.removeChild(scrollDiv); + + return scrollbarWidth; +}; + /** * Checks if `value` is the * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) @@ -722,20 +743,6 @@ function makeDataAttributeString(props) { .trim(); } -function getDefault(a, b) { - return a !== undefined ? a : b; -} - - - - - - - - - - - function copyTextToClipboard(text) { // https://stackoverflow.com/a/30810322/5353542 var textArea = document.createElement('textarea'); @@ -799,19 +806,25 @@ let throttle$1 = throttle_1; let debounce$2 = debounce_1; -function promisify(fn, context = null) { +function nextTick(fn, context = null) { return (...args) => { return new Promise(resolve => { - setTimeout(() => { + const execute = () => { const out = fn.apply(context, args); resolve(out); - }, 0); + }; + + if (window.setImmediate) { + setImmediate(execute); + } else if (window.requestAnimationFrame) { + requestAnimationFrame(execute); + } else { + setTimeout(execute); + } }); }; } - - function linkProperties(target, source, properties) { const props = properties.reduce((acc, prop) => { acc[prop] = { @@ -846,10 +859,10 @@ function ensureArray(val) { class DataManager { constructor(options) { this.options = options; - this.sortRows = promisify(this.sortRows, this); - this.switchColumn = promisify(this.switchColumn, this); - this.removeColumn = promisify(this.removeColumn, this); - this.filterRows = promisify(this.filterRows, this); + this.sortRows = nextTick(this.sortRows, this); + this.switchColumn = nextTick(this.switchColumn, this); + this.removeColumn = nextTick(this.removeColumn, this); + this.filterRows = nextTick(this.filterRows, this); } init(data, columns) { @@ -1344,6 +1357,12 @@ class DataManager { getColumn(colIndex) { colIndex = +colIndex; + + if (colIndex < 0) { + // negative indexes + colIndex = this.columns.length + colIndex; + } + return this.columns.find(col => col.colIndex === colIndex); } @@ -1664,9 +1683,8 @@ class ColumnManager { const $cell = span.closest('.data-table-cell'); let { colIndex, - sortOrder + sortOrder = 'none' } = $.data($cell); - sortOrder = getDefault(sortOrder, 'none'); const col = this.getColumn(colIndex); if (col && col.sortable === false) { @@ -1806,18 +1824,16 @@ class ColumnManager { return this.datamanager.getColumns(); } - setColumnWidth(colIndex) { + setColumnWidth(colIndex, width) { colIndex = +colIndex; this._columnWidthMap = this._columnWidthMap || []; - const { - width - } = this.getColumn(colIndex); + let columnWidth = width || this.getColumn(colIndex).width; let index = this._columnWidthMap[colIndex]; const selector = `[data-col-index="${colIndex}"] .content, [data-col-index="${colIndex}"] .edit-cell`; const styles = { - width: width + 'px' + width: columnWidth + 'px' }; index = this.style.setStyle(selector, styles, index); @@ -2620,7 +2636,7 @@ class RowManager { ]); this.bindEvents(); - this.refreshRows = promisify(this.refreshRows, this); + this.refreshRows = nextTick(this.refreshRows, this); } get datamanager() { @@ -2895,7 +2911,7 @@ class BodyRenderer { this.cellmanager = instance.cellmanager; this.bodyScrollable = instance.bodyScrollable; this.log = instance.log; - this.appendRemainingData = promisify(this.appendRemainingData, this); + this.appendRemainingData = nextTick(this.appendRemainingData, this); } render() { @@ -3016,6 +3032,7 @@ class Style { $.on(window, 'resize', throttle$1(() => { this.distributeRemainingWidth(); this.refreshColumnWidth(); + this.compensateScrollbarWidth(); this.setBodyStyle(); }, 300)); } @@ -3057,9 +3074,10 @@ class Style { this.setupMinWidth(); this.setupNaturalColumnWidth(); this.setupColumnWidth(); - this.distributeRemainingWidth(); this.setColumnStyle(); + this.compensateScrollbarWidth(); + this.setDefaultCellHeight(); this.setBodyStyle(); } @@ -3172,6 +3190,13 @@ class Style { } } + compensateScrollbarWidth() { + const scrollbarWidth = $.scrollbarWidth(); + const lastCol = this.datamanager.getColumn(-1); + const width = lastCol.width - scrollbarWidth; + this.columnmanager.setColumnWidth(lastCol.colIndex, width); + } + distributeRemainingWidth() { if (this.options.layout !== 'fluid') return; @@ -3579,7 +3604,7 @@ var name = "frappe-datatable"; var version = "0.0.2"; var description = "A modern datatable library for the web"; var main = "dist/frappe-datatable.cjs.js"; -var scripts = {"start":"npm run dev","build":"rollup -c","dev":"rollup -c -w","test":"mocha --compilers js:babel-core/register --colors ./test/*.spec.js","test:watch":"mocha --compilers js:babel-core/register --colors -w ./test/*.spec.js"}; +var scripts = {"start":"yarn run dev","build":"rollup -c","dev":"rollup -c -w","test":"mocha --compilers js:babel-core/register --colors ./test/*.spec.js","test:watch":"mocha --compilers js:babel-core/register --colors -w ./test/*.spec.js"}; var devDependencies = {"chai":"3.5.0","cssnano":"^3.10.0","deepmerge":"^2.0.1","eslint":"3.19.0","eslint-loader":"1.7.1","mocha":"3.3.0","postcss-cssnext":"^3.1.0","postcss-nested":"^3.0.0","precss":"^3.1.0","rollup-plugin-commonjs":"^8.3.0","rollup-plugin-json":"^2.3.0","rollup-plugin-node-resolve":"^3.0.3","rollup-plugin-postcss":"^1.2.8","rollup-plugin-uglify":"^3.0.0"}; var repository = {"type":"git","url":"https://github.com/frappe/datatable.git"}; var keywords = ["datatable","data","grid","table"]; diff --git a/index.html b/index.html index 8964d15..530cd1a 100644 --- a/index.html +++ b/index.html @@ -55,10 +55,9 @@ { name: "Office" }, { name: "Extn." }, { name: "Start Date" }, - { name: "Salary" }, - { name: "Blank", focusable: false, resizable: false } + { name: "Salary" } ]; - data = [[ "Tiger Nixon", {content: "System Architect", editable: false}, "Edinburgh", "5421", "2011/04/25", "$320,800", "" ], [ "Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750", "" ], [ "Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000", "" ], [ "Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "6224", "2012/03/29", "$433,060", "" ], [ "Airi Satou", "Accountant", "Tokyo", "5407", "2008/11/28", "$162,700", "" ], [ "Brielle Williamson", "Integration Specialist", "New York", "4804", "2012/12/02", "$372,000", "" ], [ "Herrod Chandler", "Sales Assistant", "San Francisco", "9608", "2012/08/06", "$137,500", "" ], [ "Rhona Davidson", "Integration Specialist", "Tokyo", "6200", "2010/10/14", "$327,900", "" ], [ "Colleen Hurst", "Javascript Developer", "San Francisco", "2360", "2009/09/15", "$205,500", "" ], [ "Sonya Frost", "Software Engineer", "Edinburgh", "1667", "2008/12/13", "$103,600", "" ], [ "Jena Gaines", "Office Manager", "London", "3814", "2008/12/19", "$90,560", "" ], [ "Quinn Flynn", "Support Lead", "Edinburgh", "9497", "2013/03/03", "$342,000", "" ], [ "Charde Marshall", "Regional Director", "San Francisco", "6741", "2008/10/16", "$470,600", "" ], [ "Haley Kennedy", "Senior Marketing Designer", "London", "3597", "2012/12/18", "$313,500", "" ], [ "Tatyana Fitzpatrick", "Regional Director", "London", "1965", "2010/03/17", "$385,750", "" ], [ "Michael Silva", "Marketing Designer", "London", "1581", "2012/11/27", "$198,500", "" ], [ "Paul Byrd", "Chief Financial Officer (CFO)", "New York", "3059", "2010/06/09", "$725,000", "" ], [ "Gloria Little", "Systems Administrator", "New York", "1721", "2009/04/10", "$237,500", "" ], [ "Bradley Greer", "Software Engineer", "London", "2558", "2012/10/13", "$132,000", "" ], [ "Dai Rios", "Personnel Lead", "Edinburgh", "2290", "2012/09/26", "$217,500", "" ], [ "Jenette Caldwell", "Development Lead", "New York", "1937", "2011/09/03", "$345,000", "" ], [ "Yuri Berry", "Chief Marketing Officer (CMO)", "New York", "6154", "2009/06/25", "$675,000", "" ], [ "Caesar Vance", "Pre-Sales Support", "New York", "8330", "2011/12/12", "$106,450", "" ], [ "Doris Wilder", "Sales Assistant", "Sidney", "3023", "2010/09/20", "$85,600", "" ], [ "Angelica Ramos", "Chief Executive Officer (CEO)", "London", "5797", "2009/10/09", "$1,200,000", "" ], [ "Gavin Joyce", "Developer", "Edinburgh", "8822", "2010/12/22", "$92,575", "" ], [ "Jennifer Chang", "Regional Director", "Singapore", "9239", "2010/11/14", "$357,650", "" ], [ "Brenden Wagner", "Software Engineer", "San Francisco", "1314", "2011/06/07", "$206,850", "" ], [ "Fiona Green", "Chief Operating Officer (COO)", "San Francisco", "2947", "2010/03/11", "$850,000", "" ], [ "Shou Itou", "Regional Marketing", "Tokyo", "8899", "2011/08/14", "$163,000", "" ], [ "Michelle House", "Integration Specialist", "Sidney", "2769", "2011/06/02", "$95,400", "" ], [ "Suki Burks", "Developer", "London", "6832", "2009/10/22", "$114,500", "" ], [ "Prescott Bartlett", "Technical Author", "London", "3606", "2011/05/07", "$145,000", "" ], [ "Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500", "" ], [ "Martena Mccray", "Post-Sales support", "Edinburgh", "8240", "2011/03/09", "$324,050", "" ], [ "Unity Butler", "Marketing Designer", "San Francisco", "5384", "2009/12/09", "$85,675", "" ], [ "Howard Hatfield", "Office Manager", "San Francisco", "7031", "2008/12/16", "$164,500", "" ], [ "Hope Fuentes", "Secretary", "San Francisco", "6318", "2010/02/12", "$109,850", "" ], [ "Vivian Harrell", "Financial Controller", "San Francisco", "9422", "2009/02/14", "$452,500", "" ], [ "Timothy Mooney", "Office Manager", "London", "7580", "2008/12/11", "$136,200", "" ], [ "Jackson Bradshaw", "Director", "New York", "1042", "2008/09/26", "$645,750", "" ], [ "Olivia Liang", "Support Engineer", "Singapore", "2120", "2011/02/03", "$234,500", "" ], [ "Bruno Nash", "Software Engineer", "London", "6222", "2011/05/03", "$163,500", "" ], [ "Sakura Yamamoto", "Support Engineer", "Tokyo", "9383", "2009/08/19", "$139,575", "" ], [ "Thor Walton", "Developer", "New York", "8327", "2013/08/11", "$98,540", "" ], [ "Finn Camacho", "Support Engineer", "San Francisco", "2927", "2009/07/07", "$87,500", "" ], [ "Serge Baldwin", "Data Coordinator", "Singapore", "8352", "2012/04/09", "$138,575", "" ], [ "Zenaida Frank", "Software Engineer", "New York", "7439", "2010/01/04", "$125,250", "" ], [ "Zorita Serrano", "Software Engineer", "San Francisco", "4389", "2012/06/01", "$115,000", "" ], [ "Jennifer Acosta", "Junior Javascript Developer", "Edinburgh", "3431", "2013/02/01", "$75,650", "" ], [ "Cara Stevens", "Sales Assistant", "New York", "3990", "2011/12/06", "$145,600", "" ], [ "Hermione Butler", "Regional Director", "London", "1016", "2011/03/21", "$356,250", "" ], [ "Lael Greer", "Systems Administrator", "London", "6733", "2009/02/27", "$103,500", "" ], [ "Jonas Alexander", "Developer", "San Francisco", "8196", "2010/07/14", "$86,500", "" ], [ "Shad Decker", "Regional Director", "Edinburgh", "6373", "2008/11/13", "$183,000", "" ], [ "Michael Bruce", "Javascript Developer", "Singapore", "5384", "2011/06/27", "$183,000", "" ], [ "Donna Snider", "Customer Support", "New York", "4226", "2011/01/25", "$112,000", "" ]]; + data = [[ "Tiger Nixon", {content: "System Architect", editable: false}, "Edinburgh", "5421", "2011/04/25", "$320,800"], [ "Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750"], [ "Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000"], [ "Cedric Kelly", "Senior Javascript Developer", "Edinburgh", "6224", "2012/03/29", "$433,060"], [ "Airi Satou", "Accountant", "Tokyo", "5407", "2008/11/28", "$162,700"], [ "Brielle Williamson", "Integration Specialist", "New York", "4804", "2012/12/02", "$372,000"], [ "Herrod Chandler", "Sales Assistant", "San Francisco", "9608", "2012/08/06", "$137,500"], [ "Rhona Davidson", "Integration Specialist", "Tokyo", "6200", "2010/10/14", "$327,900"], [ "Colleen Hurst", "Javascript Developer", "San Francisco", "2360", "2009/09/15", "$205,500"], [ "Sonya Frost", "Software Engineer", "Edinburgh", "1667", "2008/12/13", "$103,600"], [ "Jena Gaines", "Office Manager", "London", "3814", "2008/12/19", "$90,560"], [ "Quinn Flynn", "Support Lead", "Edinburgh", "9497", "2013/03/03", "$342,000"], [ "Charde Marshall", "Regional Director", "San Francisco", "6741", "2008/10/16", "$470,600"], [ "Haley Kennedy", "Senior Marketing Designer", "London", "3597", "2012/12/18", "$313,500"], [ "Tatyana Fitzpatrick", "Regional Director", "London", "1965", "2010/03/17", "$385,750"], [ "Michael Silva", "Marketing Designer", "London", "1581", "2012/11/27", "$198,500"], [ "Paul Byrd", "Chief Financial Officer (CFO)", "New York", "3059", "2010/06/09", "$725,000"], [ "Gloria Little", "Systems Administrator", "New York", "1721", "2009/04/10", "$237,500"], [ "Bradley Greer", "Software Engineer", "London", "2558", "2012/10/13", "$132,000"], [ "Dai Rios", "Personnel Lead", "Edinburgh", "2290", "2012/09/26", "$217,500"], [ "Jenette Caldwell", "Development Lead", "New York", "1937", "2011/09/03", "$345,000"], [ "Yuri Berry", "Chief Marketing Officer (CMO)", "New York", "6154", "2009/06/25", "$675,000"], [ "Caesar Vance", "Pre-Sales Support", "New York", "8330", "2011/12/12", "$106,450"], [ "Doris Wilder", "Sales Assistant", "Sidney", "3023", "2010/09/20", "$85,600"], [ "Angelica Ramos", "Chief Executive Officer (CEO)", "London", "5797", "2009/10/09", "$1,200,000"], [ "Gavin Joyce", "Developer", "Edinburgh", "8822", "2010/12/22", "$92,575"], [ "Jennifer Chang", "Regional Director", "Singapore", "9239", "2010/11/14", "$357,650"], [ "Brenden Wagner", "Software Engineer", "San Francisco", "1314", "2011/06/07", "$206,850"], [ "Fiona Green", "Chief Operating Officer (COO)", "San Francisco", "2947", "2010/03/11", "$850,000"], [ "Shou Itou", "Regional Marketing", "Tokyo", "8899", "2011/08/14", "$163,000"], [ "Michelle House", "Integration Specialist", "Sidney", "2769", "2011/06/02", "$95,400"], [ "Suki Burks", "Developer", "London", "6832", "2009/10/22", "$114,500"], [ "Prescott Bartlett", "Technical Author", "London", "3606", "2011/05/07", "$145,000"], [ "Gavin Cortez", "Team Leader", "San Francisco", "2860", "2008/10/26", "$235,500"], [ "Martena Mccray", "Post-Sales support", "Edinburgh", "8240", "2011/03/09", "$324,050"], [ "Unity Butler", "Marketing Designer", "San Francisco", "5384", "2009/12/09", "$85,675"], [ "Howard Hatfield", "Office Manager", "San Francisco", "7031", "2008/12/16", "$164,500"], [ "Hope Fuentes", "Secretary", "San Francisco", "6318", "2010/02/12", "$109,850"], [ "Vivian Harrell", "Financial Controller", "San Francisco", "9422", "2009/02/14", "$452,500"], [ "Timothy Mooney", "Office Manager", "London", "7580", "2008/12/11", "$136,200"], [ "Jackson Bradshaw", "Director", "New York", "1042", "2008/09/26", "$645,750"], [ "Olivia Liang", "Support Engineer", "Singapore", "2120", "2011/02/03", "$234,500"], [ "Bruno Nash", "Software Engineer", "London", "6222", "2011/05/03", "$163,500"], [ "Sakura Yamamoto", "Support Engineer", "Tokyo", "9383", "2009/08/19", "$139,575"], [ "Thor Walton", "Developer", "New York", "8327", "2013/08/11", "$98,540"], [ "Finn Camacho", "Support Engineer", "San Francisco", "2927", "2009/07/07", "$87,500"], [ "Serge Baldwin", "Data Coordinator", "Singapore", "8352", "2012/04/09", "$138,575"], [ "Zenaida Frank", "Software Engineer", "New York", "7439", "2010/01/04", "$125,250"], [ "Zorita Serrano", "Software Engineer", "San Francisco", "4389", "2012/06/01", "$115,000"], [ "Jennifer Acosta", "Junior Javascript Developer", "Edinburgh", "3431", "2013/02/01", "$75,650"], [ "Cara Stevens", "Sales Assistant", "New York", "3990", "2011/12/06", "$145,600"], [ "Hermione Butler", "Regional Director", "London", "1016", "2011/03/21", "$356,250"], [ "Lael Greer", "Systems Administrator", "London", "6733", "2009/02/27", "$103,500"], [ "Jonas Alexander", "Developer", "San Francisco", "8196", "2010/07/14", "$86,500"], [ "Shad Decker", "Regional Director", "Edinburgh", "6373", "2008/11/13", "$183,000"], [ "Michael Bruce", "Javascript Developer", "Singapore", "5384", "2011/06/27", "$183,000"], [ "Donna Snider", "Customer Support", "New York", "4226", "2011/01/25", "$112,000"]]; if (largeData) { diff --git a/package.json b/package.json index 757f77a..254e881 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "A modern datatable library for the web", "main": "dist/frappe-datatable.cjs.js", "scripts": { - "start": "npm run dev", + "start": "yarn run dev", "build": "rollup -c", "dev": "rollup -c -w", "test": "mocha --compilers js:babel-core/register --colors ./test/*.spec.js", diff --git a/src/columnmanager.js b/src/columnmanager.js index b91d114..978821b 100644 --- a/src/columnmanager.js +++ b/src/columnmanager.js @@ -1,7 +1,6 @@ import $ from './dom'; import Sortable from 'sortablejs'; import { - getDefault, linkProperties, debounce } from './utils'; @@ -223,9 +222,8 @@ export default class ColumnManager { const $cell = span.closest('.data-table-cell'); let { colIndex, - sortOrder + sortOrder = 'none' } = $.data($cell); - sortOrder = getDefault(sortOrder, 'none'); const col = this.getColumn(colIndex); if (col && col.sortable === false) { @@ -365,18 +363,16 @@ export default class ColumnManager { return this.datamanager.getColumns(); } - setColumnWidth(colIndex) { + setColumnWidth(colIndex, width) { colIndex = +colIndex; this._columnWidthMap = this._columnWidthMap || []; - const { - width - } = this.getColumn(colIndex); + let columnWidth = width || this.getColumn(colIndex).width; let index = this._columnWidthMap[colIndex]; const selector = `[data-col-index="${colIndex}"] .content, [data-col-index="${colIndex}"] .edit-cell`; const styles = { - width: width + 'px' + width: columnWidth + 'px' }; index = this.style.setStyle(selector, styles, index); diff --git a/src/dom.js b/src/dom.js index f930a90..8c3f91d 100644 --- a/src/dom.js +++ b/src/dom.js @@ -179,3 +179,24 @@ $.scrollTop = function scrollTop(element, pixels) { element.scrollTop = pixels; }); }; + +$.scrollbarWidth = function scrollbarWidth() { + // Create the measurement node + const scrollDiv = document.createElement('div'); + $.style(scrollDiv, { + width: '100px', + height: '100px', + overflow: 'scroll', + position: 'absolute', + top: '-9999px' + }); + document.body.appendChild(scrollDiv); + + // Get the scrollbar width + const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; + + // Delete the DIV + document.body.removeChild(scrollDiv); + + return scrollbarWidth; +}; diff --git a/src/style.js b/src/style.js index fe316f5..5b5d403 100644 --- a/src/style.js +++ b/src/style.js @@ -31,6 +31,7 @@ export default class Style { $.on(window, 'resize', throttle(() => { this.distributeRemainingWidth(); this.refreshColumnWidth(); + this.compensateScrollbarWidth(); this.setBodyStyle(); }, 300)); } @@ -72,9 +73,10 @@ export default class Style { this.setupMinWidth(); this.setupNaturalColumnWidth(); this.setupColumnWidth(); - this.distributeRemainingWidth(); this.setColumnStyle(); + this.compensateScrollbarWidth(); + this.setDefaultCellHeight(); this.setBodyStyle(); } @@ -187,6 +189,13 @@ export default class Style { } } + compensateScrollbarWidth() { + const scrollbarWidth = $.scrollbarWidth(); + const lastCol = this.datamanager.getColumn(-1); + const width = lastCol.width - scrollbarWidth; + this.columnmanager.setColumnWidth(lastCol.colIndex, width); + } + distributeRemainingWidth() { if (this.options.layout !== 'fluid') return;