LP1908763 Survey column sorting broken
authorGarry Collum <gcollum@gmail.com>
Tue, 12 Jan 2021 21:21:58 +0000 (16:21 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 9 Feb 2021 18:24:48 +0000 (13:24 -0500)
Fixes the sorting on the Administration > Local Administration > Surveys
table.

To test.
1. Create a 3 or more surveys and note that none of the columns sort.
2. Apply the patch.
3. Sorting should now work.

Signed-off-by: Garry Collum <gcollum@gmail.com>
Signed-off-by: Mike Risher <mrisher@catalyte.io>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.ts

index 9865a4b..7bec134 100644 (file)
@@ -30,6 +30,8 @@ export class SurveyComponent implements OnInit {
     @ViewChild('endSurveyFailedString', { static: true }) endSurveyFailedString: StringComponent;
     @ViewChild('endSurveySuccessString', { static: true }) endSurveySuccessString: StringComponent;
 
+    @Input() sortField: string;
+    @Input() idlClass='asv';
     @Input() dialogSize: 'sm' | 'lg' = 'lg';
 
     constructor(
@@ -44,7 +46,21 @@ export class SurveyComponent implements OnInit {
 
     ngOnInit() {
         this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
-            return this.pcrud.retrieveAll('asv', {});
+           const orderBy: any = {};
+           if (sort.length) {
+               // Sort specified from grid
+               orderBy[this.idlClass] = sort[0].name + ' ' + sort[0].dir;
+           } else if (this.sortField) {
+               // Default sort field
+               orderBy[this.idlClass] = this.sortField;
+           }
+
+           const searchOps = {
+               offset: pager.offset,
+               limit: pager.limit,
+               order_by: orderBy
+           };
+            return this.pcrud.retrieveAll('asv', searchOps, {});
         };
 
         this.grid.onRowActivate.subscribe(