From 7bac878a843c185043ce1b0d76ee13c90229bf2d Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 23 Feb 2018 15:04:18 +0530 Subject: [PATCH] Set rowIndex width based on rowCount --- dist/frappe-datatable.cjs.js | 13 +++++++++++-- dist/frappe-datatable.js | 13 +++++++++++-- src/datamanager.js | 3 +-- src/style.js | 10 ++++++++++ 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/dist/frappe-datatable.cjs.js b/dist/frappe-datatable.cjs.js index cc03883..45b81f1 100644 --- a/dist/frappe-datatable.cjs.js +++ b/dist/frappe-datatable.cjs.js @@ -880,8 +880,7 @@ class DataManager { editable: false, resizable: false, focusable: false, - dropdown: false, - width: 30 + dropdown: false }; this.columns.push(cell); @@ -2770,6 +2769,16 @@ class Style { const column = this.datamanager.getColumn(colIndex); let naturalWidth = $.style($('.content', $cell), 'width'); + + if (column.id === '_rowIndex') { + // width based on rowCount + const rowCount = this.datamanager.getRowCount(); + const digits = (rowCount + '').length; + if (digits > 2) { + naturalWidth = naturalWidth + ((digits - 2) * 8); + } + } + column.naturalWidth = naturalWidth; }); } diff --git a/dist/frappe-datatable.js b/dist/frappe-datatable.js index 4d920eb..3608296 100644 --- a/dist/frappe-datatable.js +++ b/dist/frappe-datatable.js @@ -879,8 +879,7 @@ class DataManager { editable: false, resizable: false, focusable: false, - dropdown: false, - width: 30 + dropdown: false }; this.columns.push(cell); @@ -2769,6 +2768,16 @@ class Style { const column = this.datamanager.getColumn(colIndex); let naturalWidth = $.style($('.content', $cell), 'width'); + + if (column.id === '_rowIndex') { + // width based on rowCount + const rowCount = this.datamanager.getRowCount(); + const digits = (rowCount + '').length; + if (digits > 2) { + naturalWidth = naturalWidth + ((digits - 2) * 8); + } + } + column.naturalWidth = naturalWidth; }); } diff --git a/src/datamanager.js b/src/datamanager.js index 8359c1f..4816c2a 100644 --- a/src/datamanager.js +++ b/src/datamanager.js @@ -65,8 +65,7 @@ export default class DataManager { editable: false, resizable: false, focusable: false, - dropdown: false, - width: 30 + dropdown: false }; this.columns.push(cell); diff --git a/src/style.js b/src/style.js index fdea46a..714eb49 100644 --- a/src/style.js +++ b/src/style.js @@ -124,6 +124,16 @@ export default class Style { const column = this.datamanager.getColumn(colIndex); let naturalWidth = $.style($('.content', $cell), 'width'); + + if (column.id === '_rowIndex') { + // width based on rowCount + const rowCount = this.datamanager.getRowCount(); + const digits = (rowCount + '').length; + if (digits > 2) { + naturalWidth = naturalWidth + ((digits - 2) * 8); + } + } + column.naturalWidth = naturalWidth; }); }