@azrico/reactgrid 1.5.2 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +35 -1
- package/dist/src/func/func_grid.d.ts +4 -1
- package/dist/src/func/func_grid.js +10 -3
- package/dist/src/hooks/useDatasource.js +13 -2
- package/dist/src/types/types.d.ts +15 -3
- package/index.ts +5 -0
- package/package.json +1 -1
- package/src/func/func_grid.ts +16 -3
- package/src/hooks/useDatasource.ts +32 -25
- package/src/types/types.ts +16 -2
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
|
+
|
|
5
|
+
### 1.6.0 (2026-10-14)
|
|
6
|
+
|
|
7
|
+
* Pass `filterValue`, `sortInfo` and `groupBy` to a `dataSource` function next to `skip`, `limit`, `cached_data` and `last_cache_info`, so header filters can drive a server-side search.
|
|
8
|
+
* With `gridOptions.remoteFilter` / `remoteSort`, a filter or sort change invalidates the data cache and calls `dataSource` again. Local filtering and sorting still reuse the cached rows.
|
|
9
|
+
* Export the typed `AzDataSourceParams` and `AzDataSourceFunc` for the `dataSource` and `details_dataSource` props.
|
|
10
|
+
* Re-export `SelectFilter`, `NumberFilter`, `DateFilter` and `BoolFilter` for `column.filterEditor`.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './src/views/DataGrid';
|
|
2
2
|
export * from './src/types/types';
|
|
3
3
|
export { get_row_id, set_row_id, get_col_name, get_col_header } from './src/func/func_grid';
|
|
4
|
+
export { default as SelectFilter } from '@inovua/reactdatagrid-enterprise/SelectFilter';
|
|
5
|
+
export { default as NumberFilter } from '@inovua/reactdatagrid-enterprise/NumberFilter';
|
|
6
|
+
export { default as DateFilter } from '@inovua/reactdatagrid-enterprise/DateFilter';
|
|
7
|
+
export { default as BoolFilter } from '@inovua/reactdatagrid-enterprise/BoolFilter';
|
|
4
8
|
import { AzGrid } from './src/views/DataGrid';
|
|
5
9
|
export default AzGrid;
|
package/dist/index.js
CHANGED
|
@@ -7,8 +7,36 @@ var _exportNames = {
|
|
|
7
7
|
get_row_id: true,
|
|
8
8
|
set_row_id: true,
|
|
9
9
|
get_col_name: true,
|
|
10
|
-
get_col_header: true
|
|
10
|
+
get_col_header: true,
|
|
11
|
+
SelectFilter: true,
|
|
12
|
+
NumberFilter: true,
|
|
13
|
+
DateFilter: true,
|
|
14
|
+
BoolFilter: true
|
|
11
15
|
};
|
|
16
|
+
Object.defineProperty(exports, "BoolFilter", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _BoolFilter.default;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "DateFilter", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () {
|
|
25
|
+
return _DateFilter.default;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "NumberFilter", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _NumberFilter.default;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(exports, "SelectFilter", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () {
|
|
37
|
+
return _SelectFilter.default;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
12
40
|
exports.default = void 0;
|
|
13
41
|
Object.defineProperty(exports, "get_col_header", {
|
|
14
42
|
enumerable: true,
|
|
@@ -59,4 +87,10 @@ Object.keys(_types).forEach(function (key) {
|
|
|
59
87
|
});
|
|
60
88
|
});
|
|
61
89
|
var _func_grid = require("./src/func/func_grid");
|
|
90
|
+
var _SelectFilter = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise/SelectFilter"));
|
|
91
|
+
var _NumberFilter = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise/NumberFilter"));
|
|
92
|
+
var _DateFilter = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise/DateFilter"));
|
|
93
|
+
var _BoolFilter = _interopRequireDefault(require("@inovua/reactdatagrid-enterprise/BoolFilter"));
|
|
94
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
95
|
+
// filter editors for column.filterEditor, so consumers don't import @inovua directly
|
|
62
96
|
var _default = exports.default = _DataGrid.AzGrid;
|
|
@@ -3,7 +3,10 @@ export type MakeWriteable<Type> = {
|
|
|
3
3
|
-readonly [Key in keyof Type]: Type[Key];
|
|
4
4
|
};
|
|
5
5
|
export type ModifyFields<T, R> = Omit<T, keyof R> & R;
|
|
6
|
-
export declare function ApplyDataSource(datasource: any, props: any
|
|
6
|
+
export declare function ApplyDataSource(datasource: any, props: any, remote?: {
|
|
7
|
+
remoteFilter?: boolean;
|
|
8
|
+
remoteSort?: boolean;
|
|
9
|
+
}): Promise<any>;
|
|
7
10
|
/**
|
|
8
11
|
* merges together all different props for columns
|
|
9
12
|
* to build a single final column data array
|
|
@@ -25,13 +25,17 @@ const defaultColumnOptions = {
|
|
|
25
25
|
lockable: false,
|
|
26
26
|
editable: false
|
|
27
27
|
};
|
|
28
|
-
async function ApplyDataSource(datasource, props) {
|
|
28
|
+
async function ApplyDataSource(datasource, props, remote = {}) {
|
|
29
29
|
let result_data = undefined;
|
|
30
30
|
let isUsingCache = false;
|
|
31
|
+
//filter/sort are only part of the key when they are sent to a remote dataSource,
|
|
32
|
+
//local filtering/sorting keeps reusing the cached rows
|
|
31
33
|
const cacheInfo = {
|
|
32
34
|
ds: datasource,
|
|
33
35
|
skip: props.skip,
|
|
34
|
-
limit: props.limit
|
|
36
|
+
limit: props.limit,
|
|
37
|
+
filterValue: remote.remoteFilter ? props.filterValue : undefined,
|
|
38
|
+
sortInfo: remote.remoteSort ? props.sortInfo : undefined
|
|
35
39
|
};
|
|
36
40
|
//check if we can used cached data
|
|
37
41
|
//if the datasource is changed since last render, we should invalidate cache
|
|
@@ -284,7 +288,10 @@ function get_default_key() {
|
|
|
284
288
|
}
|
|
285
289
|
//check if two cache objects are the same
|
|
286
290
|
function validateCache(current, old, looseCheck = false) {
|
|
287
|
-
|
|
291
|
+
//deep compare skip/limit/filterValue/sortInfo, array order matters (sort priority)
|
|
292
|
+
if (!old || !(0, _object.object_equals)(current, old, {
|
|
293
|
+
strictArrayCheck: true
|
|
294
|
+
})) return false;
|
|
288
295
|
if (looseCheck) return true;
|
|
289
296
|
if (current.ds != old.ds) return false;
|
|
290
297
|
return true;
|
|
@@ -8,14 +8,25 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
8
8
|
var _func_grid = require("../func/func_grid");
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
function useDataSource(ds, props) {
|
|
11
|
+
var _props$gridOptions, _props$gridOptions2;
|
|
11
12
|
const cached_data = _react.default.useRef();
|
|
12
13
|
const last_cache_info = _react.default.useRef();
|
|
14
|
+
// filter/sort only change the result when the grid sends them to the dataSource
|
|
15
|
+
const remoteFilter = !!(props !== null && props !== void 0 && (_props$gridOptions = props.gridOptions) !== null && _props$gridOptions !== void 0 && _props$gridOptions.remoteFilter);
|
|
16
|
+
const remoteSort = !!(props !== null && props !== void 0 && (_props$gridOptions2 = props.gridOptions) !== null && _props$gridOptions2 !== void 0 && _props$gridOptions2.remoteSort);
|
|
13
17
|
return _react.default.useCallback(async dt => {
|
|
14
|
-
|
|
18
|
+
const params = {
|
|
15
19
|
skip: dt === null || dt === void 0 ? void 0 : dt.skip,
|
|
16
20
|
limit: dt === null || dt === void 0 ? void 0 : dt.limit,
|
|
21
|
+
filterValue: dt === null || dt === void 0 ? void 0 : dt.filterValue,
|
|
22
|
+
sortInfo: dt === null || dt === void 0 ? void 0 : dt.sortInfo,
|
|
23
|
+
groupBy: dt === null || dt === void 0 ? void 0 : dt.groupBy,
|
|
17
24
|
cached_data: cached_data,
|
|
18
25
|
last_cache_info: last_cache_info
|
|
26
|
+
};
|
|
27
|
+
return await (0, _func_grid.ApplyDataSource)(ds, params, {
|
|
28
|
+
remoteFilter,
|
|
29
|
+
remoteSort
|
|
19
30
|
});
|
|
20
|
-
}, [ds]);
|
|
31
|
+
}, [ds, remoteFilter, remoteSort]);
|
|
21
32
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModifyFields } from '../func/func_grid';
|
|
2
2
|
import { ConvertableToMenuItem } from '@azrico/controls/context-menu';
|
|
3
3
|
import React from 'react';
|
|
4
|
-
import { TypeCellSelection, TypeColumn, TypeDataGridProps, TypeDataSource, TypeEditInfo, TypeFilterTypes, TypeFilterValue, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection, TypeComputedProps } from '@inovua/reactdatagrid-community/types';
|
|
4
|
+
import { TypeCellSelection, TypeColumn, TypeDataGridProps, TypeDataSource, TypeEditInfo, TypeFilterTypes, TypeFilterValue, TypeRowDetailsInfo, TypeRowProps, TypeRowSelection, TypeComputedProps, TypeSortInfo, TypeGroupBy } from '@inovua/reactdatagrid-community/types';
|
|
5
5
|
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
6
6
|
export type ColumnDefinition = TypeColumn;
|
|
7
7
|
export type CellDefinition = any;
|
|
@@ -44,9 +44,21 @@ export type AzGridOptions = Partial<TypeDataGridProps> & {
|
|
|
44
44
|
[key: string]: any;
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
|
+
/** arguments passed to a dataSource function */
|
|
48
|
+
export type AzDataSourceParams = {
|
|
49
|
+
skip?: number;
|
|
50
|
+
limit?: number;
|
|
51
|
+
/** current header filters, filter.value is an array of selected ids for a multi-select SelectFilter */
|
|
52
|
+
filterValue?: TypeFilterValue;
|
|
53
|
+
sortInfo?: TypeSortInfo;
|
|
54
|
+
groupBy?: TypeGroupBy;
|
|
55
|
+
cached_data: React.MutableRefObject<any>;
|
|
56
|
+
last_cache_info: React.MutableRefObject<any>;
|
|
57
|
+
};
|
|
58
|
+
export type AzDataSourceFunc = (args: AzDataSourceParams) => any[] | Promise<any[] | any>;
|
|
47
59
|
export type AzGridProps = {
|
|
48
|
-
dataSource?: any[] |
|
|
49
|
-
details_dataSource?: any[] |
|
|
60
|
+
dataSource?: any[] | AzDataSourceFunc;
|
|
61
|
+
details_dataSource?: any[] | AzDataSourceFunc;
|
|
50
62
|
details_columns?: LooseColumnDefinition[];
|
|
51
63
|
details_filter?: FilterValues;
|
|
52
64
|
licenseKey?: string;
|
package/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export * from './src/views/DataGrid';
|
|
2
2
|
export * from './src/types/types';
|
|
3
3
|
export { get_row_id, set_row_id, get_col_name, get_col_header } from './src/func/func_grid';
|
|
4
|
+
// filter editors for column.filterEditor, so consumers don't import @inovua directly
|
|
5
|
+
export { default as SelectFilter } from '@inovua/reactdatagrid-enterprise/SelectFilter';
|
|
6
|
+
export { default as NumberFilter } from '@inovua/reactdatagrid-enterprise/NumberFilter';
|
|
7
|
+
export { default as DateFilter } from '@inovua/reactdatagrid-enterprise/DateFilter';
|
|
8
|
+
export { default as BoolFilter } from '@inovua/reactdatagrid-enterprise/BoolFilter';
|
|
4
9
|
|
|
5
10
|
import { AzGrid } from './src/views/DataGrid';
|
|
6
11
|
export default AzGrid;
|
package/package.json
CHANGED
package/src/func/func_grid.ts
CHANGED
|
@@ -17,12 +17,24 @@ const defaultColumnOptions: ColumnDefinition = {
|
|
|
17
17
|
editable: false,
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export async function ApplyDataSource(
|
|
20
|
+
export async function ApplyDataSource(
|
|
21
|
+
datasource,
|
|
22
|
+
props,
|
|
23
|
+
remote: { remoteFilter?: boolean; remoteSort?: boolean } = {}
|
|
24
|
+
) {
|
|
21
25
|
let result_data: any = undefined;
|
|
22
26
|
|
|
23
27
|
let isUsingCache = false;
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
//filter/sort are only part of the key when they are sent to a remote dataSource,
|
|
30
|
+
//local filtering/sorting keeps reusing the cached rows
|
|
31
|
+
const cacheInfo = {
|
|
32
|
+
ds: datasource,
|
|
33
|
+
skip: props.skip,
|
|
34
|
+
limit: props.limit,
|
|
35
|
+
filterValue: remote.remoteFilter ? props.filterValue : undefined,
|
|
36
|
+
sortInfo: remote.remoteSort ? props.sortInfo : undefined,
|
|
37
|
+
};
|
|
26
38
|
//check if we can used cached data
|
|
27
39
|
//if the datasource is changed since last render, we should invalidate cache
|
|
28
40
|
if (!validateCache(props.last_cache_info.current, cacheInfo, props.looseCacheCheck)) {
|
|
@@ -289,7 +301,8 @@ export function get_default_key() {
|
|
|
289
301
|
|
|
290
302
|
//check if two cache objects are the same
|
|
291
303
|
export function validateCache(current: any, old: any, looseCheck = false) {
|
|
292
|
-
|
|
304
|
+
//deep compare skip/limit/filterValue/sortInfo, array order matters (sort priority)
|
|
305
|
+
if (!old || !object_equals(current, old, { strictArrayCheck: true })) return false;
|
|
293
306
|
|
|
294
307
|
if (looseCheck) return true;
|
|
295
308
|
|
|
@@ -1,25 +1,32 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { AzGridProps, DataGridWrapperProps, GridType } from '../types/types';
|
|
3
|
-
import {
|
|
4
|
-
applyColumnData,
|
|
5
|
-
ApplyDataSource,
|
|
6
|
-
find_realData,
|
|
7
|
-
get_row_id,
|
|
8
|
-
} from '../func/func_grid';
|
|
9
|
-
import { func_selection } from '../func/func_child';
|
|
10
|
-
|
|
11
|
-
export function useDataSource(ds: any, props: AzGridProps) {
|
|
12
|
-
const cached_data = React.useRef<any>();
|
|
13
|
-
const last_cache_info = React.useRef<any>();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AzDataSourceParams, AzGridProps, DataGridWrapperProps, GridType } from '../types/types';
|
|
3
|
+
import {
|
|
4
|
+
applyColumnData,
|
|
5
|
+
ApplyDataSource,
|
|
6
|
+
find_realData,
|
|
7
|
+
get_row_id,
|
|
8
|
+
} from '../func/func_grid';
|
|
9
|
+
import { func_selection } from '../func/func_child';
|
|
10
|
+
|
|
11
|
+
export function useDataSource(ds: any, props: AzGridProps) {
|
|
12
|
+
const cached_data = React.useRef<any>();
|
|
13
|
+
const last_cache_info = React.useRef<any>();
|
|
14
|
+
// filter/sort only change the result when the grid sends them to the dataSource
|
|
15
|
+
const remoteFilter = !!props?.gridOptions?.remoteFilter;
|
|
16
|
+
const remoteSort = !!props?.gridOptions?.remoteSort;
|
|
17
|
+
return React.useCallback(
|
|
18
|
+
async (dt) => {
|
|
19
|
+
const params: AzDataSourceParams = {
|
|
20
|
+
skip: dt?.skip,
|
|
21
|
+
limit: dt?.limit,
|
|
22
|
+
filterValue: dt?.filterValue,
|
|
23
|
+
sortInfo: dt?.sortInfo,
|
|
24
|
+
groupBy: dt?.groupBy,
|
|
25
|
+
cached_data: cached_data,
|
|
26
|
+
last_cache_info: last_cache_info,
|
|
27
|
+
};
|
|
28
|
+
return await ApplyDataSource(ds, params, { remoteFilter, remoteSort });
|
|
29
|
+
},
|
|
30
|
+
[ds, remoteFilter, remoteSort]
|
|
31
|
+
);
|
|
32
|
+
}
|
package/src/types/types.ts
CHANGED
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
TypeRowProps,
|
|
14
14
|
TypeRowSelection,
|
|
15
15
|
TypeComputedProps,
|
|
16
|
+
TypeSortInfo,
|
|
17
|
+
TypeGroupBy,
|
|
16
18
|
} from '@inovua/reactdatagrid-community/types';
|
|
17
19
|
|
|
18
20
|
import { TypeOnSelectionChangeArg } from '@inovua/reactdatagrid-community/types/TypeDataGridProps';
|
|
@@ -58,10 +60,22 @@ export type AzGridOptions = Partial<TypeDataGridProps> & {
|
|
|
58
60
|
/** extra DOM props for the header row */
|
|
59
61
|
headerProps?: { [key: string]: any };
|
|
60
62
|
};
|
|
63
|
+
/** arguments passed to a dataSource function */
|
|
64
|
+
export type AzDataSourceParams = {
|
|
65
|
+
skip?: number;
|
|
66
|
+
limit?: number;
|
|
67
|
+
/** current header filters, filter.value is an array of selected ids for a multi-select SelectFilter */
|
|
68
|
+
filterValue?: TypeFilterValue;
|
|
69
|
+
sortInfo?: TypeSortInfo;
|
|
70
|
+
groupBy?: TypeGroupBy;
|
|
71
|
+
cached_data: React.MutableRefObject<any>;
|
|
72
|
+
last_cache_info: React.MutableRefObject<any>;
|
|
73
|
+
};
|
|
74
|
+
export type AzDataSourceFunc = (args: AzDataSourceParams) => any[] | Promise<any[] | any>;
|
|
61
75
|
/* -------------------------------------------------------------------------- */
|
|
62
76
|
export type AzGridProps = {
|
|
63
|
-
dataSource?: any[] |
|
|
64
|
-
details_dataSource?: any[] |
|
|
77
|
+
dataSource?: any[] | AzDataSourceFunc;
|
|
78
|
+
details_dataSource?: any[] | AzDataSourceFunc; //details is rendered under each row
|
|
65
79
|
details_columns?: LooseColumnDefinition[];
|
|
66
80
|
details_filter?: FilterValues;
|
|
67
81
|
|