diff --git a/package.json b/package.json index 4ccd198e..ce521f49 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ka-table", - "version": "8.8.1", + "version": "8.9.0", "license": "MIT", "repository": "github:komarovalexander/ka-table", "homepage": "https://komarovalexander.github.io/ka-table/#/overview", diff --git a/src/lib/Utils/PropsUtils.test.ts b/src/lib/Utils/PropsUtils.test.ts index 4bd99856..96c763d1 100644 --- a/src/lib/Utils/PropsUtils.test.ts +++ b/src/lib/Utils/PropsUtils.test.ts @@ -11,6 +11,7 @@ import { areAllVisibleRowsSelected, getData, getDraggableProps, + getFilteredData, getPagesCountByProps, getSelectedData, groupPanelOnDrop, @@ -754,3 +755,22 @@ describe('isValid', () => { ).toBeTruthy(); }); }); + +describe('getFilteredData', () => { + const propsInit: ITableProps = { + data: [ + { id: 1, field: '11' }, + { id: 2, field: '21' }, + { id: 3, field: '33' }, + ], + rowKeyField: 'id', + columns: [{ + key: 'field', + filterRowValue: '1' + }], + }; + it('default', () => { + const result = getFilteredData(propsInit); + expect(result).toMatchSnapshot(); + }); +}); diff --git a/src/lib/Utils/PropsUtils.ts b/src/lib/Utils/PropsUtils.ts index 1de1bc51..0ec2faba 100644 --- a/src/lib/Utils/PropsUtils.ts +++ b/src/lib/Utils/PropsUtils.ts @@ -63,6 +63,10 @@ export function mergeProps( return mergedResult; }; +export const getFilteredData = (props: ITableProps) => { + return filterAndSearchData(props); +} + export const areAllFilteredRowsSelected = (props: ITableProps) => { const { selectedRows = [], rowKeyField } = props; return filterAndSearchData(props).every(d => selectedRows.includes(getValueByField(d, rowKeyField))) diff --git a/src/lib/Utils/__snapshots__/PropsUtils.test.ts.snap b/src/lib/Utils/__snapshots__/PropsUtils.test.ts.snap index fbe3c234..e15c953c 100644 --- a/src/lib/Utils/__snapshots__/PropsUtils.test.ts.snap +++ b/src/lib/Utils/__snapshots__/PropsUtils.test.ts.snap @@ -263,6 +263,19 @@ Array [ ] `; +exports[`getFilteredData default 1`] = ` +Array [ + Object { + "field": "11", + "id": 1, + }, + Object { + "field": "21", + "id": 2, + }, +] +`; + exports[`getSelectedData one item 1`] = ` Array [ Object {