UNPKG

rb-data-table

Version:
132 lines 4.14 kB
import { Row } from './row'; import { Column } from './column'; var DataSet = /** @class */ (function () { function DataSet(data, columnSettings) { if (data === void 0) { data = []; } this.columnSettings = columnSettings; this.data = []; this.columns = []; this.rows = []; this.willSelect = 'first'; this.createColumns(columnSettings); this.setData(data); this.createNewRow(); } DataSet.prototype.setData = function (data) { this.data = data; this.createRows(); }; DataSet.prototype.getColumns = function () { return this.columns; }; DataSet.prototype.getRows = function () { return this.rows; }; DataSet.prototype.getFirstRow = function () { return this.rows[0]; }; DataSet.prototype.getLastRow = function () { return this.rows[this.rows.length - 1]; }; DataSet.prototype.findRowByData = function (data) { return this.rows.find(function (row) { return row.getData() === data; }); }; DataSet.prototype.deselectAll = function () { this.rows.forEach(function (row) { row.isSelected = false; }); }; DataSet.prototype.selectRow = function (row) { var previousIsSelected = row.isSelected; this.deselectAll(); row.isSelected = !previousIsSelected; this.selectedRow = row; return this.selectedRow; }; DataSet.prototype.multipleSelectRow = function (row) { row.isSelected = !row.isSelected; this.selectedRow = row; return this.selectedRow; }; DataSet.prototype.multipeSelectNoToggle = function (row) { row.isSelected = true; this.selectedRow = row; return this.selectedRow; }; DataSet.prototype.selectPreviousRow = function () { if (this.rows.length > 0) { var index = this.selectedRow ? this.selectedRow.index : 0; if (index > this.rows.length - 1) { index = this.rows.length - 1; } this.selectRow(this.rows[index]); return this.selectedRow; } }; DataSet.prototype.selectFirstRow = function () { if (this.rows.length > 0) { this.selectRow(this.rows[0]); return this.selectedRow; } }; DataSet.prototype.selectLastRow = function () { if (this.rows.length > 0) { this.selectRow(this.rows[this.rows.length - 1]); return this.selectedRow; } }; DataSet.prototype.willSelectFirstRow = function () { this.willSelect = 'first'; }; DataSet.prototype.willSelectLastRow = function () { this.willSelect = 'last'; }; DataSet.prototype.select = function () { if (this.getRows().length === 0) { return; } if (this.willSelect) { if (this.willSelect === 'first') { this.selectFirstRow(); } if (this.willSelect === 'last') { this.selectLastRow(); } this.willSelect = ''; } else { this.selectFirstRow(); } return this.selectedRow; }; DataSet.prototype.createNewRow = function () { this.newRow = new Row(-1, {}, this); this.newRow.isInEditing = true; }; /** * Create columns by mapping from the settings * @param settings * @private */ DataSet.prototype.createColumns = function (settings) { for (var id in settings) { if (settings.hasOwnProperty(id)) { this.columns.push(new Column(id, settings[id], this)); } } }; /** * Create rows based on current data prepared in data source * @private */ DataSet.prototype.createRows = function () { var _this = this; this.rows = []; this.data.forEach(function (el, index) { _this.rows.push(new Row(index, el, _this)); }); }; return DataSet; }()); export { DataSet }; //# sourceMappingURL=data-set.js.map