Mercurial > hg > ng2-query-ismi
comparison app/query-result-table.component.ts @ 42:99fb5a953a40
fixed issues with paging and sorting.
author | casties |
---|---|
date | Wed, 17 Feb 2016 17:59:11 +0100 |
parents | 739eb38ec2a2 |
children | dc4f0541f04d |
comparison
equal
deleted
inserted
replaced
41:5353b2dffb0f | 42:99fb5a953a40 |
---|---|
45 (pageChanged)="onChangeTable(config, $event)" | 45 (pageChanged)="onChangeTable(config, $event)" |
46 (numPages)="numPages = $event"> | 46 (numPages)="numPages = $event"> |
47 </pagination> | 47 </pagination> |
48 <ngTable | 48 <ngTable |
49 [config]="config.sorting" | 49 [config]="config.sorting" |
50 (tableChanged)="onChangeTable(config)" | 50 (tableChanged)="onChangeTable($event)" |
51 [rows]="rows" [columns]="columns"> | 51 [rows]="rows" [columns]="columns"> |
52 </ngTable> | 52 </ngTable> |
53 </div> | 53 </div> |
54 </div> | 54 </div> |
55 `, | 55 `, |
56 inputs: ['queryState', 'resultInfo'], | 56 inputs: ['queryState', 'resultInfo'], |
57 directives: [NG_TABLE_DIRECTIVES, PAGINATION_DIRECTIVES] | 57 directives: [NG_TABLE_DIRECTIVES, PAGINATION_DIRECTIVES] |
58 }) | 58 }) |
59 | 59 |
60 export class QueryResultTableComponent implements OnInit { | 60 export class QueryResultTableComponent implements OnInit { |
61 | 61 |
62 public queryState: QueryState; | 62 public queryState: QueryState; |
63 public resultInfo: string; | 63 public resultInfo: string; |
64 | 64 |
85 console.debug("result table changed! changes=", changes); | 85 console.debug("result table changed! changes=", changes); |
86 this.data = this.queryState.results; | 86 this.data = this.queryState.results; |
87 this.allColumns = this.queryState.resultColumns; | 87 this.allColumns = this.queryState.resultColumns; |
88 this.columns = this.allColumns.filter(c => c.show); | 88 this.columns = this.allColumns.filter(c => c.show); |
89 this.config.sorting = this.columns; | 89 this.config.sorting = this.columns; |
90 this.config.paging = {'page': this.page, 'itemsPerPage': this.itemsPerPage}; | |
90 this.showTable = (this.data.length < 1000); | 91 this.showTable = (this.data.length < 1000); |
91 this.onChangeTable(this.config, null); | 92 this.onChangeTable(this.config); |
92 } | 93 } |
93 | 94 |
94 ngOnInit() { | 95 ngOnInit() { |
95 console.debug("result table init!"); | 96 console.debug("result table init!"); |
96 } | 97 } |
102 if (num == 0) { | 103 if (num == 0) { |
103 this.itemsPerPage = this.length; | 104 this.itemsPerPage = this.length; |
104 } else { | 105 } else { |
105 this.itemsPerPage = num; | 106 this.itemsPerPage = num; |
106 } | 107 } |
108 // update something | |
109 this.config.paging = {'page': this.page, 'itemsPerPage': this.itemsPerPage}; | |
110 this.onChangeTable(this.config); | |
107 } | 111 } |
108 | 112 |
109 onSelectCols(event: any) { | 113 onSelectCols(event: any) { |
110 console.debug("select cols:", this.allColumns); | 114 console.debug("select cols:", this.allColumns); |
111 this.columns = this.allColumns.filter(c => c.show); | 115 this.columns = this.allColumns.filter(c => c.show); |
149 | 153 |
150 return filteredData; | 154 return filteredData; |
151 } | 155 } |
152 | 156 |
153 onChangeTable(config, page: any = config.paging) { | 157 onChangeTable(config, page: any = config.paging) { |
154 console.debug("onChangeTable config=", config); | 158 console.debug("onChangeTable config=", config, " page=", page); |
155 if (config.filtering) { | 159 if (config.filtering) { |
156 Object.assign(this.config.filtering, config.filtering); | 160 Object.assign(this.config.filtering, config.filtering); |
157 } | 161 } |
158 if (config.sorting) { | 162 if (config.sorting) { |
159 Object.assign(this.config.sorting, config.sorting); | 163 Object.assign(this.config.sorting, config.sorting); |
164 // changing sorting resets page | |
165 if (page == null) { | |
166 this.page = 1; | |
167 page = {'page': this.page, 'itemsPerPage': this.itemsPerPage}; | |
168 } | |
160 } | 169 } |
161 | 170 |
162 //let filteredData = this.changeFilter(this.data, this.config); | 171 //let filteredData = this.changeFilter(this.data, this.config); |
163 //let sortedData = this.changeSort(filteredData, this.config); | 172 //let sortedData = this.changeSort(filteredData, this.config); |
164 let sortedData = this.changeSort(this.data, this.config); | 173 let sortedData = this.changeSort(this.data, this.config); |
165 | 174 |
166 this.rows = (page && config.paging) ? this.changePage(page, sortedData) : sortedData; | 175 this.rows = (page && this.config.paging) ? this.changePage(page, sortedData) : sortedData; |
167 this.length = sortedData.length; | 176 this.length = sortedData.length; |
168 } | 177 } |
169 | 178 |
170 } | 179 } |