ngp-sort-pipe
Version:
Angular sort/orderby pipe, order one dimensional array or an array of objects
55 lines (49 loc) • 1.41 kB
JavaScript
import { __decorate } from 'tslib';
import { Pipe, NgModule } from '@angular/core';
import { orderBy } from 'lodash';
var SortByPipe = /** @class */ (function () {
function SortByPipe() {
}
SortByPipe.prototype.transform = function (value, order, column) {
if (order === void 0) { order = ''; }
if (column === void 0) { column = ''; }
if (!value || order === '' || !order) {
return value;
} // no array
if (!column || column === '') {
if (order === 'asc') {
return value.sort();
}
else {
return value.sort().reverse();
}
} // sort 1d array
if (value.length <= 1) {
return value;
} // array with only one item
return orderBy(value, [column], [order]);
};
SortByPipe = __decorate([
Pipe({ name: 'sortBy' })
], SortByPipe);
return SortByPipe;
}());
var NgpSortModule = /** @class */ (function () {
function NgpSortModule() {
}
NgpSortModule = __decorate([
NgModule({
declarations: [SortByPipe],
exports: [SortByPipe]
})
], NgpSortModule);
return NgpSortModule;
}());
/*
* Public API Surface of ngp-sort
*/
/**
* Generated bundle index. Do not edit.
*/
export { NgpSortModule, SortByPipe };
//# sourceMappingURL=ngp-sort-pipe.js.map