Код: Выделить всё
@Component({
selector: 'app-my-table',
templateUrl: './my-table.component.html',
})
export class MyTableComponent implements OnInit {
dtOptions: DataTables.Settings = {};
data: any[] = []; // This will hold the data for Angular rendering
constructor(private http: HttpClient) {}
ngOnInit(): void {
this.dtOptions = {
serverSide: true,
processing: true,
ajax: (dataTablesParameters: any, callback) => {
this.http
.post('/api/your-data-endpoint', dataTablesParameters)
.subscribe((resp) => {
this.data = resp.data; // Update Angular's data array
callback({
recordsTotal: resp.recordsTotal,
recordsFiltered: resp.recordsFiltered,
data: [], // Return empty array for DataTables which causes rendering of the tag to be done by angular.
});
});
},
columns: [
{ data: 'property1' },
{ data: 'property2'}
]
};
}
}
Column 1
Column 2
{{ item.property1 }}
#mytable td.dt-empty {
display:none;
}
Как настроить datatable так, чтобы она отображала tbody из HTML вместо конфигурации столбцов в машинописном скрипте?
Подробнее здесь: https://stackoverflow.com/questions/798 ... low-render
Мобильная версия