minor fixes
This commit is contained in:
parent
9ae7c3a8e6
commit
0d7fc93b37
21
index.html
21
index.html
File diff suppressed because one or more lines are too long
@ -2571,7 +2571,7 @@ var DataManager = function () {
|
|||||||
content: '',
|
content: '',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
editable: false,
|
editable: false,
|
||||||
resizable: true,
|
resizable: false,
|
||||||
focusable: false,
|
focusable: false,
|
||||||
dropdown: false
|
dropdown: false
|
||||||
};
|
};
|
||||||
@ -2582,15 +2582,12 @@ var DataManager = function () {
|
|||||||
if (this.options.addCheckboxColumn && !this.hasColumnById('_checkbox')) {
|
if (this.options.addCheckboxColumn && !this.hasColumnById('_checkbox')) {
|
||||||
var _val = {
|
var _val = {
|
||||||
id: '_checkbox',
|
id: '_checkbox',
|
||||||
content: 'Checkbox',
|
content: this.getCheckboxHTML(),
|
||||||
editable: false,
|
editable: false,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
sortable: false,
|
sortable: false,
|
||||||
focusable: false,
|
focusable: false,
|
||||||
dropdown: false,
|
dropdown: false
|
||||||
format: function format(val) {
|
|
||||||
return '<input type="checkbox" />';
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
columns = [_val].concat(columns);
|
columns = [_val].concat(columns);
|
||||||
@ -2618,7 +2615,7 @@ var DataManager = function () {
|
|||||||
value: function prepareRows() {
|
value: function prepareRows() {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
this.validateRows(this.data);
|
this.validateData(this.data);
|
||||||
|
|
||||||
this.rows = this.data.map(function (d, i) {
|
this.rows = this.data.map(function (d, i) {
|
||||||
var index = _this._getNextRowCount();
|
var index = _this._getNextRowCount();
|
||||||
@ -2627,13 +2624,12 @@ var DataManager = function () {
|
|||||||
|
|
||||||
if (Array.isArray(d)) {
|
if (Array.isArray(d)) {
|
||||||
// row is an array
|
// row is an array
|
||||||
if (_this.options.addSerialNoColumn) {
|
|
||||||
row.push(index + 1 + '');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_this.options.addCheckboxColumn) {
|
if (_this.options.addCheckboxColumn) {
|
||||||
row.push(_this.getCheckboxHTML());
|
row.push(_this.getCheckboxHTML());
|
||||||
}
|
}
|
||||||
|
if (_this.options.addSerialNoColumn) {
|
||||||
|
row.push(index + 1 + '');
|
||||||
|
}
|
||||||
row = row.concat(d);
|
row = row.concat(d);
|
||||||
} else {
|
} else {
|
||||||
// row is a dict
|
// row is a dict
|
||||||
@ -2645,10 +2641,10 @@ var DataManager = function () {
|
|||||||
for (var _iterator = _this.columns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
for (var _iterator = _this.columns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||||
var col = _step.value;
|
var col = _step.value;
|
||||||
|
|
||||||
if (col.id === '_rowIndex') {
|
if (col.id === '_checkbox') {
|
||||||
row.push(index + 1 + '');
|
|
||||||
} else if (col.id === '_checkbox') {
|
|
||||||
row.push(_this.getCheckboxHTML());
|
row.push(_this.getCheckboxHTML());
|
||||||
|
} else if (col.id === '_rowIndex') {
|
||||||
|
row.push(index + 1 + '');
|
||||||
} else {
|
} else {
|
||||||
row.push(col.format(d[col.id]));
|
row.push(col.format(d[col.id]));
|
||||||
}
|
}
|
||||||
@ -2686,16 +2682,17 @@ var DataManager = function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'validateRows',
|
key: 'validateData',
|
||||||
value: function validateRows(rows) {
|
value: function validateData(data) {
|
||||||
if (!Array.isArray(rows)) {
|
if (Array.isArray(data) && (Array.isArray(data[0]) || _typeof(data[0]) === 'object')) {
|
||||||
throw new DataError('`rows` must be an array');
|
return true;
|
||||||
}
|
}
|
||||||
|
throw new DataError('`data` must be an array of arrays or objects');
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'appendRows',
|
key: 'appendRows',
|
||||||
value: function appendRows(rows) {
|
value: function appendRows(rows) {
|
||||||
this.validateRows(rows);
|
this.validateData(rows);
|
||||||
|
|
||||||
this.rows = this.rows.concat(this.prepareRows(rows));
|
this.rows = this.rows.concat(this.prepareRows(rows));
|
||||||
}
|
}
|
||||||
@ -3057,6 +3054,9 @@ function _prepareColumns(columns) {
|
|||||||
|
|
||||||
return columns.map(prepareCell).map(function (col) {
|
return columns.map(prepareCell).map(function (col) {
|
||||||
return Object.assign({}, baseColumn, col);
|
return Object.assign({}, baseColumn, col);
|
||||||
|
}).map(function (col) {
|
||||||
|
col.id = col.id || col.content;
|
||||||
|
return col;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -44,7 +44,7 @@ export default class DataManager {
|
|||||||
content: '',
|
content: '',
|
||||||
align: 'center',
|
align: 'center',
|
||||||
editable: false,
|
editable: false,
|
||||||
resizable: true,
|
resizable: false,
|
||||||
focusable: false,
|
focusable: false,
|
||||||
dropdown: false
|
dropdown: false
|
||||||
};
|
};
|
||||||
@ -55,13 +55,12 @@ export default class DataManager {
|
|||||||
if (this.options.addCheckboxColumn && !this.hasColumnById('_checkbox')) {
|
if (this.options.addCheckboxColumn && !this.hasColumnById('_checkbox')) {
|
||||||
const val = {
|
const val = {
|
||||||
id: '_checkbox',
|
id: '_checkbox',
|
||||||
content: 'Checkbox',
|
content: this.getCheckboxHTML(),
|
||||||
editable: false,
|
editable: false,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
sortable: false,
|
sortable: false,
|
||||||
focusable: false,
|
focusable: false,
|
||||||
dropdown: false,
|
dropdown: false
|
||||||
format: val => '<input type="checkbox" />'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
columns = [val].concat(columns);
|
columns = [val].concat(columns);
|
||||||
@ -85,7 +84,7 @@ export default class DataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
prepareRows() {
|
prepareRows() {
|
||||||
this.validateRows(this.data);
|
this.validateData(this.data);
|
||||||
|
|
||||||
this.rows = this.data.map((d, i) => {
|
this.rows = this.data.map((d, i) => {
|
||||||
const index = this._getNextRowCount();
|
const index = this._getNextRowCount();
|
||||||
@ -94,22 +93,21 @@ export default class DataManager {
|
|||||||
|
|
||||||
if (Array.isArray(d)) {
|
if (Array.isArray(d)) {
|
||||||
// row is an array
|
// row is an array
|
||||||
if (this.options.addSerialNoColumn) {
|
|
||||||
row.push((index + 1) + '');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.addCheckboxColumn) {
|
if (this.options.addCheckboxColumn) {
|
||||||
row.push(this.getCheckboxHTML());
|
row.push(this.getCheckboxHTML());
|
||||||
}
|
}
|
||||||
|
if (this.options.addSerialNoColumn) {
|
||||||
|
row.push((index + 1) + '');
|
||||||
|
}
|
||||||
row = row.concat(d);
|
row = row.concat(d);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// row is a dict
|
// row is a dict
|
||||||
for (let col of this.columns) {
|
for (let col of this.columns) {
|
||||||
if (col.id === '_rowIndex') {
|
if (col.id === '_checkbox') {
|
||||||
row.push((index + 1) + '');
|
|
||||||
} else if (col.id === '_checkbox') {
|
|
||||||
row.push(this.getCheckboxHTML());
|
row.push(this.getCheckboxHTML());
|
||||||
|
} else if (col.id === '_rowIndex') {
|
||||||
|
row.push((index + 1) + '');
|
||||||
} else {
|
} else {
|
||||||
row.push(col.format(d[col.id]));
|
row.push(col.format(d[col.id]));
|
||||||
}
|
}
|
||||||
@ -132,14 +130,15 @@ export default class DataManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
validateRows(rows) {
|
validateData(data) {
|
||||||
if (!Array.isArray(rows)) {
|
if (Array.isArray(data) && (Array.isArray(data[0]) || typeof data[0] === 'object')) {
|
||||||
throw new DataError('`rows` must be an array');
|
return true;
|
||||||
}
|
}
|
||||||
|
throw new DataError('`data` must be an array of arrays or objects');
|
||||||
}
|
}
|
||||||
|
|
||||||
appendRows(rows) {
|
appendRows(rows) {
|
||||||
this.validateRows(rows);
|
this.validateData(rows);
|
||||||
|
|
||||||
this.rows = this.rows.concat(this.prepareRows(rows));
|
this.rows = this.rows.concat(this.prepareRows(rows));
|
||||||
}
|
}
|
||||||
@ -443,7 +442,11 @@ function prepareColumns(columns, props = {}) {
|
|||||||
|
|
||||||
return columns
|
return columns
|
||||||
.map(prepareCell)
|
.map(prepareCell)
|
||||||
.map(col => Object.assign({}, baseColumn, col));
|
.map(col => Object.assign({}, baseColumn, col))
|
||||||
|
.map(col => {
|
||||||
|
col.id = col.id || col.content;
|
||||||
|
return col;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareCell(col, i) {
|
function prepareCell(col, i) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user