salix/front/core/components/table/index.js

60 lines
1.4 KiB
JavaScript
Raw Normal View History

import ngModule from '../../module';
import './style.scss';
export default class Table {
constructor($scope, $element, $transclude) {
this.$scope = $scope;
this.table = $element[0];
this.field = null;
this.order = null;
}
setOrder(field, order) {
this.field = field;
this.order = order;
}
2018-07-16 06:00:04 +00:00
applyOrder(field = this.field, order = this.order) {
2018-11-27 14:02:54 +00:00
if (field && order) {
this.model.order = `${field} ${order}`;
this.setActiveArrow();
}
2018-07-16 06:00:04 +00:00
this.model.refresh();
}
2021-05-11 07:43:15 +00:00
isScrollable() {
return this.table.classList.contains('scrollable');
}
$postLink() {
if (this.isScrollable()) {
const childCells = this.table.querySelector('vn-tbody');
console.log(childCells);
}
}
setActiveArrow() {
let columns = this.table.querySelectorAll('vn-thead vn-th');
columns.forEach(column => {
column.classList.remove('active');
});
let selector = `vn-thead vn-th[field="${this.field}"]`;
let activeColumn = this.table.querySelector(selector);
activeColumn.classList.add('active');
}
}
Table.$inject = ['$scope', '$element', '$transclude'];
ngModule.vnComponent('vnTable', {
template: require('./index.html'),
transclude: true,
controller: Table,
bindings: {
2018-11-27 14:02:54 +00:00
model: '<?',
autoLoad: '<?'
}
});