import { Component } from '@angular/core';
@Component({
selector: 'single-selection-demo',
template: `
This demonstrates a simple single selection table with the 3rd row selected by default.
Selections
-
{{sel.name}}
- No Selections
`
})
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);
}
updateRowPosition() {
const ix = this.getSelectedIx();
const arr = [ ...this.rows ];
arr[ix - 1] = this.rows[ix];
arr[ix] = this.rows[ix - 1];
this.rows = arr;
}
getSelectedIx() {
return this.selected[0]['$$index'];
}
}