angular2-data-table
Version:
angular2-data-table is a Angular2 component for presenting large and complex data.
82 lines (73 loc) • 1.64 kB
text/typescript
import { Component } from '@angular/core';
export class ColumnToggleComponent {
rows = [
{
name: 'Claudine Neal',
gender: 'female',
company: 'Sealoud'
},
{
name: 'Beryl Rice',
gender: 'female',
company: 'Velity'
}
];
columns = [
{ name: 'Name' },
{ name: 'Gender' },
{ name: 'Company' }
];
allColumns = [
{ name: 'Name' },
{ name: 'Gender' },
{ name: 'Company' }
];
toggle(col) {
const isChecked = this.isChecked(col);
if(isChecked) {
this.columns = this.columns.filter(c => {
return c.name !== col.name;
});
} else {
this.columns = [...this.columns, col];
}
}
isChecked(col) {
return this.columns.find(c => {
return c.name === col.name;
});
}
}