angular2-data-table
Version:
angular2-data-table is a Angular2 component for presenting large and complex data.
80 lines (66 loc) • 1.69 kB
text/typescript
import { Component } from '@angular/core';
@Component({
selector: 'single-selection-demo',
template: `
<div>
<h3>Single Row Selection</h3>
<div style='float:left;width:75%'>
<div class="info">
<p>This demonstrates a simple single selection table with the 3rd row selected by default.</p>
</div>
<swui-datatable
class="material"
[]="rows"
[]="'force'"
[]="columns"
[]="50"
[]="50"
[]="'auto'"
[]="5"
[]="selected"
[]="'single'"
(activate)="onActivate($event)"
(select)='onSelect($event)'>
</swui-datatable>
</div>
<div class='selected-column'>
<h4>Selections</h4>
<ul>
<li *ngFor='let sel of selected'>
{{sel.name}}
</li>
<li *ngIf="!selected.length">No Selections</li>
</ul>
</div>
</div>
`
})
export class SingleSelectionComponent {
rows = [];
selected = [];
columns: any[] = [
{ prop: 'name'} ,
{ name: 'Company' },
{ name: 'Gender' }
];
constructor() {
this.fetch((data) => {
this.selected = [data[2]];
this.rows = data;
});
}
fetch(cb) {
const req = new XMLHttpRequest();
req.open('GET', `assets/data/company.json`);
req.onload = () => {
cb(JSON.parse(req.response));
};
req.send();
}
onSelect({ selected }) {
console.log('Select Event', selected, this.selected);
}
onActivate(event) {
console.log('Activate Event', event);
}
}