Mercurial > hg > ng2-query-ismi
changeset 42:99fb5a953a40
fixed issues with paging and sorting.
author | casties |
---|---|
date | Wed, 17 Feb 2016 17:59:11 +0100 |
parents | 5353b2dffb0f |
children | 39edd27d83e4 |
files | app/query-result-table.component.ts |
diffstat | 1 files changed, 14 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/app/query-result-table.component.ts Mon Feb 15 17:05:07 2016 +0100 +++ b/app/query-result-table.component.ts Wed Feb 17 17:59:11 2016 +0100 @@ -47,7 +47,7 @@ </pagination> <ngTable [config]="config.sorting" - (tableChanged)="onChangeTable(config)" + (tableChanged)="onChangeTable($event)" [rows]="rows" [columns]="columns"> </ngTable> </div> @@ -56,7 +56,7 @@ inputs: ['queryState', 'resultInfo'], directives: [NG_TABLE_DIRECTIVES, PAGINATION_DIRECTIVES] }) - + export class QueryResultTableComponent implements OnInit { public queryState: QueryState; @@ -87,8 +87,9 @@ this.allColumns = this.queryState.resultColumns; this.columns = this.allColumns.filter(c => c.show); this.config.sorting = this.columns; + this.config.paging = {'page': this.page, 'itemsPerPage': this.itemsPerPage}; this.showTable = (this.data.length < 1000); - this.onChangeTable(this.config, null); + this.onChangeTable(this.config); } ngOnInit() { @@ -104,6 +105,9 @@ } else { this.itemsPerPage = num; } + // update something + this.config.paging = {'page': this.page, 'itemsPerPage': this.itemsPerPage}; + this.onChangeTable(this.config); } onSelectCols(event: any) { @@ -151,19 +155,24 @@ } onChangeTable(config, page: any = config.paging) { - console.debug("onChangeTable config=", config); + console.debug("onChangeTable config=", config, " page=", page); if (config.filtering) { Object.assign(this.config.filtering, config.filtering); } if (config.sorting) { Object.assign(this.config.sorting, config.sorting); + // changing sorting resets page + if (page == null) { + this.page = 1; + page = {'page': this.page, 'itemsPerPage': this.itemsPerPage}; + } } //let filteredData = this.changeFilter(this.data, this.config); //let sortedData = this.changeSort(filteredData, this.config); let sortedData = this.changeSort(this.data, this.config); - this.rows = (page && config.paging) ? this.changePage(page, sortedData) : sortedData; + this.rows = (page && this.config.paging) ? this.changePage(page, sortedData) : sortedData; this.length = sortedData.length; }