I see that support for datatables in angular 2 is very poor. DataTables does not work for me (known unresolved issue) so I thought that I will write something simple for myself. By the way I will learn something useful. I want to build my table in this way:
<my-table>
<my-table-row *ngFor="let row of rows">
<my-table-col>{{row.col1}}</my-table-col>
<my-table-col>{{row.col2}}</my-table-col>
</my-table-row>
</my-table>
So I have created a component with simple filter input. Now, I would like to filter over my table. Angular should in some way assign data from my-table-col(s) to some variable (maybe 2way data binding will be useful?), then I would use some function triggered by keyup event to filter and data should update automatically but I do not know how to do that.
import { Component, Input, OnInit } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'my-table',
template: `
<div style="width: 100%">
<div style="float: left; height: 50px; width: 100%">
Search: <input type="text" [(ngModel)]="filterValue" style="height: 30px; border: 1px solid silver"/> {{filterValue}}
</div>
<div style="float: left; width: 100%">
<table>
<ng-content></ng-content>
</table>
</div>
</div>
`
})
export class MyTableComponent {
filterValue: string;
}
@Component({
selector: 'my-table-row',
template: `
<tr><ng-content></ng-content></tr>
`
})
export class MyTableRowComponent {
}
@Component({
selector: 'my-table-col',
template: `
<td><ng-content></ng-content></td>
`
})
export class MyTableColComponent {
}
Regards