i'm trying to make a sorting function and pipe for a table by following this link and here is the plunker of that example. From the example that i'm following the table header should be clickable and do the sort() function. My pipe name is prdSort. I'm also using ngx-pagination but i don't think that the main cause of this error.
//part of service.ts
productList: AngularFireList < any > ;
//end
//component.ts
productList: Product[];
isDesc: boolean = false;
column: string = 'prdName';
records = this.productList
sort(property) {
this.isDesc = !this.isDesc; //change the direction
this.column = property;
let direction = this.isDesc ? 1 : -1;
};
<!-- table header -->
<th (click)="sort('prdName')">Name</th>
<!--table row-->
<tr *ngFor="let product of productList | paginate: { itemsPerPage: 3, currentPage: p } | prdSort: {property: column, direction: direction} ">
//pipe.ts
transform(records: any, args ? : any): any {
return records.sort(function(a, b) {
if (records !== undefined) {
if (a[args.property] < b[args.property]) {
return -1 * args.direction;
} else if (a[args.property] > b[args.property]) {
return 1 * args.direction;
} else {
return 0;
}
}
return records;
});
};
I alse already included the pipe file to app.module.ts. Please let me know if more snippets are needed.
console. Just copy paste please. Looking at your titlesort of undefinedpoints to that in your piperecordsis undefined so sort can't be executed.ERROR TypeError: Cannot read property 'sort' of undefined at PrdSortPipe.transform (prd-sort.pipe.ts:13) at checkAndUpdatePureExpressionInline (core.js:12899) at checkAndUpdateNodeInline (core.js:13602) at checkAndUpdateNode (core.js:13541) at debugCheckAndUpdateNode (core.js:14413) at debugCheckDirectivesFn (core.js:14354) at Object.eval [as updateDirectives] (ProductComponent.html:63) at Object.debugUpdateDirectives [as updateDirectives] (core.js:14339) at checkAndUpdateView (core.js:13508) at callViewAction (core.js:13858)