@frui.ts/data
Advanced tools
Comparing version 1.0.0-alpha.2 to 1.0.0-alpha.3
@@ -0,2 +1,5 @@ | ||
import { SortingDirection } from "./sortingDirection"; | ||
import type { IPagingFilter } from "./types"; | ||
export declare function applySort(filter: IPagingFilter, columnName: string): void; | ||
export declare function getSortingDirection(filter: IPagingFilter, columnName: string): SortingDirection | undefined; | ||
export declare function setSort(filter: IPagingFilter, columnName: string, direction?: SortingDirection): void; | ||
export declare function addSort(filter: IPagingFilter, columnName: string, direction?: SortingDirection): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.applySort = void 0; | ||
exports.addSort = exports.setSort = exports.getSortingDirection = void 0; | ||
var sortingDirection_1 = require("./sortingDirection"); | ||
function applySort(filter, columnName) { | ||
if (filter.sortColumn === columnName) { | ||
filter.sortDirection = | ||
filter.sortDirection === sortingDirection_1.SortingDirection.Ascending ? sortingDirection_1.SortingDirection.Descending : sortingDirection_1.SortingDirection.Ascending; | ||
function getSortingDirection(filter, columnName) { | ||
var _a, _b; | ||
var existingIndex = (_a = filter.sorting) === null || _a === void 0 ? void 0 : _a.findIndex(function (x) { return x.column === columnName; }); | ||
if (existingIndex === undefined || existingIndex < 0) { | ||
return undefined; | ||
} | ||
return (_b = filter.sorting) === null || _b === void 0 ? void 0 : _b[existingIndex].direction; | ||
} | ||
exports.getSortingDirection = getSortingDirection; | ||
function setSort(filter, columnName, direction) { | ||
var _a; | ||
var existingSort = (_a = filter.sorting) === null || _a === void 0 ? void 0 : _a[0]; | ||
var sortDirection = direction !== null && direction !== void 0 ? direction : ((existingSort === null || existingSort === void 0 ? void 0 : existingSort.column) === columnName && existingSort.direction === sortingDirection_1.SortingDirection.Ascending | ||
? sortingDirection_1.SortingDirection.Descending | ||
: sortingDirection_1.SortingDirection.Ascending); | ||
if (filter.sorting) { | ||
filter.sorting[0] = { column: columnName, direction: sortDirection }; | ||
filter.sorting.length = 1; | ||
} | ||
else { | ||
filter.sortColumn = columnName; | ||
filter.sortDirection = sortingDirection_1.SortingDirection.Ascending; | ||
filter.sorting = [{ column: columnName, direction: sortDirection }]; | ||
} | ||
} | ||
exports.applySort = applySort; | ||
exports.setSort = setSort; | ||
function addSort(filter, columnName, direction) { | ||
if (!filter.sorting) { | ||
filter.sorting = [{ column: columnName, direction: direction !== null && direction !== void 0 ? direction : sortingDirection_1.SortingDirection.Ascending }]; | ||
return; | ||
} | ||
var existingIndex = filter.sorting.findIndex(function (x) { return x.column === columnName; }); | ||
if (existingIndex === -1) { | ||
filter.sorting.push({ column: columnName, direction: direction !== null && direction !== void 0 ? direction : sortingDirection_1.SortingDirection.Ascending }); | ||
} | ||
else { | ||
filter.sorting[existingIndex].direction = | ||
direction !== null && direction !== void 0 ? direction : (filter.sorting[existingIndex].direction === sortingDirection_1.SortingDirection.Ascending | ||
? sortingDirection_1.SortingDirection.Descending | ||
: sortingDirection_1.SortingDirection.Ascending); | ||
} | ||
} | ||
exports.addSort = addSort; | ||
//# sourceMappingURL=sortingHelper.js.map |
import type { SortingDirection } from "./sortingDirection"; | ||
export interface IPagingInfo { | ||
totalItems: number; | ||
offset: number; | ||
limit: number; | ||
readonly totalItems: number; | ||
readonly offset: number; | ||
readonly limit: number; | ||
} | ||
@@ -10,5 +10,7 @@ export interface IPagingFilter { | ||
limit: number; | ||
sortColumn?: string; | ||
sortDirection?: SortingDirection; | ||
sorting?: { | ||
column: string; | ||
direction: SortingDirection; | ||
}[]; | ||
} | ||
export declare type PagedQueryResult<TEntity> = [TEntity[], IPagingInfo]; |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "1.0.0-alpha.2", | ||
"version": "1.0.0-alpha.3", | ||
"description": "Helpers and interfaces for handling paged and sorted data sets", | ||
@@ -37,3 +37,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "99546362efd91f923e743ed07477bb6ef0b1caa3" | ||
"gitHead": "6ec9e7bcdb60a72fe3fe4d63a458702e33487801" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16648
139