Skip to content

Commit

Permalink
Merge pull request #390 from komarovalexander/dev
Browse files Browse the repository at this point in the history
Add getFilteredData to PropsUtils
  • Loading branch information
komarovalexander authored Mar 1, 2024
2 parents a9f7f56 + 6606196 commit b5875b7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 20 additions & 0 deletions src/lib/Utils/PropsUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
areAllVisibleRowsSelected,
getData,
getDraggableProps,
getFilteredData,
getPagesCountByProps,
getSelectedData,
groupPanelOnDrop,
Expand Down Expand Up @@ -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();
});
});
4 changes: 4 additions & 0 deletions src/lib/Utils/PropsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ export function mergeProps<T = HTMLElement>(
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)))
Expand Down
13 changes: 13 additions & 0 deletions src/lib/Utils/__snapshots__/PropsUtils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b5875b7

Please sign in to comment.