We've used ng2-table and bring rows and column(names) from server. The columns (Names, Count and Order can change). How to change columns eg. you have 2 columns SSN and Name and then you have something like Title, Name and SSN in this order and then you should have again only SSN and Name.
In first change:
SSN and Name => Title, Name and SSN
there is not seen columns as expected, but SSN, Name and Title.
In second change :
Title, Name and SSN (seen SSN, Name and Title) => SSN and Name
there is not seen columns as expected, but SSN, Name and Title (and all the values in column Title are 'undefined' (yes, we don't bring value for Title, because we don't expect there is column for Title).
There is our code. What else should we do?
public updateTable(): void {
this.tableService.getTable(this.mySettings).subscribe(obj => {
this.config = {
paging: true,
sorting: { columns: obj.columns },
filtering: { filterString: '' },
className: ['table-striped', 'table-bordered'],
selectedRowClass: 'selectedRow'
};
this.columns =obj.columns;
this.data = obj.rows;
this.length = this.data.length;
this.onChangeTable(this.config);
}
);
}
public onChangeTable(config: any, page: any = { page: this.page, itemsPerPage: this.itemsPerPage }): any {
if (config.filtering) {
Object.assign(this.config.filtering, config.filtering);
}
if (config.sorting) {
Object.assign(this.config.sorting, config.sorting);
}
let filteredData = this.changeFilter(this.data, this.config);
let sortedData = this.changeSort(filteredData, this.config);
this.rows = page && config.paging ? this.changePage(page, sortedData) : sortedData;
this.length = sortedData.length;
}