Skip to content

Commit 65a37d9

Browse files
[2.4.1] - enablePredefinedSort property (#36)
`enablePredefinedSort` property allows to ignore the sorting on the first column performed when the orderBy option is not specified. In order to not have a "breaking-change" on the current table behavior, when `enablePredefinedSort` prop is _not_ specified the data-table will be sorted as performed until now (hence sorted by the first sortable column), otherwise it is not sorted, so that a "custom predefined" sorting can be applied.
1 parent ce67558 commit 65a37d9

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### dependabot: \#33 Bump loader-utils from 1.4.0 to 1.4.2
1111

12+
## [2.4.1] - 2023-05-25
13+
14+
### Added
15+
16+
- the prop `enablePredefinedSort` to all tables. Set boolean condition for which the orderBy option should be ignored. Set as `false` by default if not specified.
17+
1218
## [2.4.0] - 2023-05-17
1319

1420
### Added

src/lib/DataTable/DataTable.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export function DataTableStaticRouted<T, TRouteNames>({
3131
hideIfEmpty = false,
3232
tableClassName,
3333
tableStyle,
34+
enablePredefinedSort = false,
3435
}: DataTableStaticRoutedProps<T, TRouteNames>) {
3536
if (hideIfEmpty === true && (!data || data.length <= 0)) return <React.Fragment />;
3637

@@ -50,6 +51,7 @@ export function DataTableStaticRouted<T, TRouteNames>({
5051
showPaging={showPaging}
5152
tableClassName={tableClassName}
5253
tableStyle={tableStyle}
54+
enablePredefinedSort={enablePredefinedSort}
5355
/>
5456
</React.Fragment>
5557
);
@@ -70,6 +72,7 @@ export function DataTableStatic<T>({
7072
hideIfEmpty = false,
7173
tableClassName,
7274
tableStyle,
75+
enablePredefinedSort = false,
7376
}: DataTableStaticProps<T>) {
7477
if (hideIfEmpty === true && (!data || data.length <= 0)) return <React.Fragment />;
7578

@@ -89,6 +92,7 @@ export function DataTableStatic<T>({
8992
showPaging={showPaging}
9093
tableClassName={tableClassName}
9194
tableStyle={tableStyle}
95+
enablePredefinedSort={enablePredefinedSort}
9296
/>
9397
</React.Fragment>
9498
);
@@ -113,6 +117,7 @@ export function DataTable<T, TFilter>({
113117
tableStyle,
114118
asc,
115119
orderBy,
120+
enablePredefinedSort = false,
116121
}: DataTableProps<T, TFilter>) {
117122
return (
118123
<DataTableRouted<T, TFilter, T>
@@ -134,6 +139,7 @@ export function DataTable<T, TFilter>({
134139
tableStyle={tableStyle}
135140
asc={asc}
136141
orderBy={orderBy}
142+
enablePredefinedSort={enablePredefinedSort}
137143
/>
138144
);
139145
}

src/lib/DataTable/DataTableInterfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface CommonDataTableProps<T> {
1717
tableClassName?: string;
1818
tableStyle?: React.CSSProperties;
1919
rowHighlight?: RowHighlightInterface<T>;
20+
enablePredefinedSort?: boolean;
2021
}
2122

2223
export interface DataTableRoutedProps<T, TFilter, TRouteName> extends CommonDataTableProps<T> {

src/lib/DataTable/DataTableRouted.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ export function DataTableRouted<T, TFilter, TRouteNames>({
3434
asc = true,
3535
orderBy,
3636
rowHighlight,
37+
enablePredefinedSort = false,
3738
}: DataTableRoutedProps<T, TFilter, TRouteNames>) {
3839
const [queryResult, setQueryResult] = useState<TableQueryResult<T>>(data);
3940
const [filterState, setFilterState] = useState<FilterPageState>({
4041
currentPage: 1,
4142
filter: predefinedFilter ?? {},
4243
itemsPerPage: predefinedItemsPerPage ?? 25,
4344
});
44-
const [orderState, setOrderState] = useState<OrderOption>({ orderBy: orderBy ?? columns[0].dataField, asc });
45+
const [orderState, setOrderState] = useState<OrderOption>({
46+
orderBy: orderBy ?? (enablePredefinedSort ? undefined : columns[0].dataField),
47+
asc,
48+
});
4549
const filterRefs = useRef<Filters>({});
4650

4751
function loadPage(filter: any, limit?: number, page?: number, orderBy?: string, asc?: boolean) {

0 commit comments

Comments
 (0)