Better handling of 0 rows

This commit is contained in:
Faris Ansari 2018-03-30 07:12:41 +05:30
parent f2ab07f516
commit e5af37fb07
9 changed files with 126 additions and 75 deletions

View File

@ -1838,7 +1838,10 @@ class ColumnManager {
};
index = this.style.setStyle(selector, styles, index);
this._columnWidthMap[colIndex] = index;
if (index !== undefined) {
this._columnWidthMap[colIndex] = index;
}
}
setColumnHeaderWidth(colIndex) {
@ -2938,7 +2941,11 @@ class BodyRenderer {
renderBodyWithClusterize() {
// first page
const rows = this.datamanager.getRowsForView(0, 20);
const initialData = this.getDataForClusterize(rows);
let initialData = this.getDataForClusterize(rows);
if (initialData.length === 0) {
initialData = [`<tr class="no-data"><td>${this.options.noDataMessage}</td></tr>`];
}
if (!this.clusterize) {
// empty body
@ -2960,8 +2967,7 @@ class BodyRenderer {
}
},
/* eslint-disable */
no_data_text: this.options.noDataMessage,
no_data_class: 'empty-state'
show_no_data_row: false,
/* eslint-enable */
});
@ -3023,11 +3029,14 @@ class Style {
const styleEl = document.createElement('style');
instance.wrapper.insertBefore(styleEl, instance.datatableWrapper);
this.styleEl = styleEl;
this.styleSheet = styleEl.sheet;
this.bindResizeWindow();
}
get stylesheet() {
return this.styleEl.sheet;
}
bindResizeWindow() {
if (this.options.layout === 'fluid') {
$.on(window, 'resize', throttle$1(() => {
@ -3059,14 +3068,16 @@ class Style {
let ruleString = `${prefixedSelector} { ${styles} }`;
let _index = this.styleSheet.cssRules.length;
if (!this.stylesheet) return;
let _index = this.stylesheet.cssRules.length;
if (index !== -1) {
this.styleSheet.deleteRule(index);
this.stylesheet.deleteRule(index);
_index = index;
}
this.styleSheet.insertRule(ruleString, _index);
return _index;
this.stylesheet.insertRule(ruleString, _index);
return _index; // eslint-disable-line
}
setDimensions() {
@ -3218,8 +3229,10 @@ class Style {
setDefaultCellHeight() {
if (this.__cellHeightSet) return;
const height = this.options.cellHeight ||
$.style($('.data-table-cell', this.instance.datatableWrapper), 'height');
const $firstCell = $('.data-table-cell', this.instance.bodyScrollable);
if (!$firstCell) return;
const height = this.options.cellHeight || $.style($firstCell, 'height');
if (height) {
this.setCellHeight(height);
this.__cellHeightSet = true;
@ -3272,7 +3285,8 @@ class Style {
});
$.style($('table', this.bodyScrollable), {
margin: 0
margin: 0,
width: '100%'
});
}
@ -3443,12 +3457,8 @@ class DataTable {
this.options || {}, options
);
this.options.headerDropdown =
DEFAULT_OPTIONS.headerDropdown
.concat(
this.options.headerDropdown || [],
options.headerDropdown || []
);
this.options.headerDropdown
.push(...(options.headerDropdown || []));
// custom user events
this.events = Object.assign(
@ -3602,7 +3612,7 @@ class DataTable {
DataTable.instances = 0;
var name = "frappe-datatable";
var version = "0.0.2";
var version = "0.0.3";
var description = "A modern datatable library for the web";
var main = "dist/frappe-datatable.cjs.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"};

View File

@ -108,6 +108,12 @@
background-color: #f5f7fa;
}
.body-scrollable .no-data td {
text-align: center;
padding: 8px;
padding: 0.5rem;
}
.data-table-header {
position: absolute;
top: 0;

View File

@ -1837,7 +1837,10 @@ class ColumnManager {
};
index = this.style.setStyle(selector, styles, index);
this._columnWidthMap[colIndex] = index;
if (index !== undefined) {
this._columnWidthMap[colIndex] = index;
}
}
setColumnHeaderWidth(colIndex) {
@ -2937,7 +2940,11 @@ class BodyRenderer {
renderBodyWithClusterize() {
// first page
const rows = this.datamanager.getRowsForView(0, 20);
const initialData = this.getDataForClusterize(rows);
let initialData = this.getDataForClusterize(rows);
if (initialData.length === 0) {
initialData = [`<tr class="no-data"><td>${this.options.noDataMessage}</td></tr>`];
}
if (!this.clusterize) {
// empty body
@ -2959,8 +2966,7 @@ class BodyRenderer {
}
},
/* eslint-disable */
no_data_text: this.options.noDataMessage,
no_data_class: 'empty-state'
show_no_data_row: false,
/* eslint-enable */
});
@ -3022,11 +3028,14 @@ class Style {
const styleEl = document.createElement('style');
instance.wrapper.insertBefore(styleEl, instance.datatableWrapper);
this.styleEl = styleEl;
this.styleSheet = styleEl.sheet;
this.bindResizeWindow();
}
get stylesheet() {
return this.styleEl.sheet;
}
bindResizeWindow() {
if (this.options.layout === 'fluid') {
$.on(window, 'resize', throttle$1(() => {
@ -3058,14 +3067,16 @@ class Style {
let ruleString = `${prefixedSelector} { ${styles} }`;
let _index = this.styleSheet.cssRules.length;
if (!this.stylesheet) return;
let _index = this.stylesheet.cssRules.length;
if (index !== -1) {
this.styleSheet.deleteRule(index);
this.stylesheet.deleteRule(index);
_index = index;
}
this.styleSheet.insertRule(ruleString, _index);
return _index;
this.stylesheet.insertRule(ruleString, _index);
return _index; // eslint-disable-line
}
setDimensions() {
@ -3217,8 +3228,10 @@ class Style {
setDefaultCellHeight() {
if (this.__cellHeightSet) return;
const height = this.options.cellHeight ||
$.style($('.data-table-cell', this.instance.datatableWrapper), 'height');
const $firstCell = $('.data-table-cell', this.instance.bodyScrollable);
if (!$firstCell) return;
const height = this.options.cellHeight || $.style($firstCell, 'height');
if (height) {
this.setCellHeight(height);
this.__cellHeightSet = true;
@ -3271,7 +3284,8 @@ class Style {
});
$.style($('table', this.bodyScrollable), {
margin: 0
margin: 0,
width: '100%'
});
}
@ -3442,12 +3456,8 @@ class DataTable {
this.options || {}, options
);
this.options.headerDropdown =
DEFAULT_OPTIONS.headerDropdown
.concat(
this.options.headerDropdown || [],
options.headerDropdown || []
);
this.options.headerDropdown
.push(...(options.headerDropdown || []));
// custom user events
this.events = Object.assign(
@ -3601,7 +3611,7 @@ class DataTable {
DataTable.instances = 0;
var name = "frappe-datatable";
var version = "0.0.2";
var version = "0.0.3";
var description = "A modern datatable library for the web";
var main = "dist/frappe-datatable.cjs.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"};

View File

@ -1837,7 +1837,10 @@ class ColumnManager {
};
index = this.style.setStyle(selector, styles, index);
this._columnWidthMap[colIndex] = index;
if (index !== undefined) {
this._columnWidthMap[colIndex] = index;
}
}
setColumnHeaderWidth(colIndex) {
@ -2937,7 +2940,11 @@ class BodyRenderer {
renderBodyWithClusterize() {
// first page
const rows = this.datamanager.getRowsForView(0, 20);
const initialData = this.getDataForClusterize(rows);
let initialData = this.getDataForClusterize(rows);
if (initialData.length === 0) {
initialData = [`<tr class="no-data"><td>${this.options.noDataMessage}</td></tr>`];
}
if (!this.clusterize) {
// empty body
@ -2959,8 +2966,7 @@ class BodyRenderer {
}
},
/* eslint-disable */
no_data_text: this.options.noDataMessage,
no_data_class: 'empty-state'
show_no_data_row: false,
/* eslint-enable */
});
@ -3022,11 +3028,14 @@ class Style {
const styleEl = document.createElement('style');
instance.wrapper.insertBefore(styleEl, instance.datatableWrapper);
this.styleEl = styleEl;
this.styleSheet = styleEl.sheet;
this.bindResizeWindow();
}
get stylesheet() {
return this.styleEl.sheet;
}
bindResizeWindow() {
if (this.options.layout === 'fluid') {
$.on(window, 'resize', throttle$1(() => {
@ -3058,14 +3067,16 @@ class Style {
let ruleString = `${prefixedSelector} { ${styles} }`;
let _index = this.styleSheet.cssRules.length;
if (!this.stylesheet) return;
let _index = this.stylesheet.cssRules.length;
if (index !== -1) {
this.styleSheet.deleteRule(index);
this.stylesheet.deleteRule(index);
_index = index;
}
this.styleSheet.insertRule(ruleString, _index);
return _index;
this.stylesheet.insertRule(ruleString, _index);
return _index; // eslint-disable-line
}
setDimensions() {
@ -3217,8 +3228,10 @@ class Style {
setDefaultCellHeight() {
if (this.__cellHeightSet) return;
const height = this.options.cellHeight ||
$.style($('.data-table-cell', this.instance.datatableWrapper), 'height');
const $firstCell = $('.data-table-cell', this.instance.bodyScrollable);
if (!$firstCell) return;
const height = this.options.cellHeight || $.style($firstCell, 'height');
if (height) {
this.setCellHeight(height);
this.__cellHeightSet = true;
@ -3271,7 +3284,8 @@ class Style {
});
$.style($('table', this.bodyScrollable), {
margin: 0
margin: 0,
width: '100%'
});
}
@ -3442,12 +3456,8 @@ class DataTable {
this.options || {}, options
);
this.options.headerDropdown =
DEFAULT_OPTIONS.headerDropdown
.concat(
this.options.headerDropdown || [],
options.headerDropdown || []
);
this.options.headerDropdown
.push(...(options.headerDropdown || []));
// custom user events
this.events = Object.assign(
@ -3601,7 +3611,7 @@ class DataTable {
DataTable.instances = 0;
var name = "frappe-datatable";
var version = "0.0.2";
var version = "0.0.3";
var description = "A modern datatable library for the web";
var main = "dist/frappe-datatable.cjs.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"};

View File

@ -39,7 +39,11 @@ export default class BodyRenderer {
renderBodyWithClusterize() {
// first page
const rows = this.datamanager.getRowsForView(0, 20);
const initialData = this.getDataForClusterize(rows);
let initialData = this.getDataForClusterize(rows);
if (initialData.length === 0) {
initialData = [`<tr class="no-data"><td>${this.options.noDataMessage}</td></tr>`];
}
if (!this.clusterize) {
// empty body
@ -61,8 +65,7 @@ export default class BodyRenderer {
}
},
/* eslint-disable */
no_data_text: this.options.noDataMessage,
no_data_class: 'empty-state'
show_no_data_row: false,
/* eslint-enable */
});

View File

@ -376,7 +376,10 @@ export default class ColumnManager {
};
index = this.style.setStyle(selector, styles, index);
this._columnWidthMap[colIndex] = index;
if (index !== undefined) {
this._columnWidthMap[colIndex] = index;
}
}
setColumnHeaderWidth(colIndex) {

View File

@ -46,12 +46,8 @@ class DataTable {
this.options || {}, options
);
this.options.headerDropdown =
DEFAULT_OPTIONS.headerDropdown
.concat(
this.options.headerDropdown || [],
options.headerDropdown || []
);
this.options.headerDropdown
.push(...(options.headerDropdown || []));
// custom user events
this.events = Object.assign(

View File

@ -108,6 +108,11 @@
&.row-highlight-all .data-table-row:not(.row-unhighlight) {
background-color: var(--light-bg);
}
.no-data td {
text-align: center;
padding: var(--spacer-2);
}
}
.data-table-header {

View File

@ -21,11 +21,14 @@ export default class Style {
const styleEl = document.createElement('style');
instance.wrapper.insertBefore(styleEl, instance.datatableWrapper);
this.styleEl = styleEl;
this.styleSheet = styleEl.sheet;
this.bindResizeWindow();
}
get stylesheet() {
return this.styleEl.sheet;
}
bindResizeWindow() {
if (this.options.layout === 'fluid') {
$.on(window, 'resize', throttle(() => {
@ -57,14 +60,16 @@ export default class Style {
let ruleString = `${prefixedSelector} { ${styles} }`;
let _index = this.styleSheet.cssRules.length;
if (!this.stylesheet) return;
let _index = this.stylesheet.cssRules.length;
if (index !== -1) {
this.styleSheet.deleteRule(index);
this.stylesheet.deleteRule(index);
_index = index;
}
this.styleSheet.insertRule(ruleString, _index);
return _index;
this.stylesheet.insertRule(ruleString, _index);
return _index; // eslint-disable-line
}
setDimensions() {
@ -216,8 +221,10 @@ export default class Style {
setDefaultCellHeight() {
if (this.__cellHeightSet) return;
const height = this.options.cellHeight ||
$.style($('.data-table-cell', this.instance.bodyScrollable), 'height');
const $firstCell = $('.data-table-cell', this.instance.bodyScrollable);
if (!$firstCell) return;
const height = this.options.cellHeight || $.style($firstCell, 'height');
if (height) {
this.setCellHeight(height);
this.__cellHeightSet = true;
@ -270,7 +277,8 @@ export default class Style {
});
$.style($('table', this.bodyScrollable), {
margin: 0
margin: 0,
width: '100%'
});
}