@bsol-oss/react-datatable5 1.0.23 → 1.0.24

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/dist/index.d.ts CHANGED
@@ -1,9 +1,18 @@
1
1
  /// <reference types="react" />
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
- import { ColumnDef } from '@tanstack/react-table';
3
+ import { FilterFn, ColumnDef } from '@tanstack/react-table';
4
+ import { RankingInfo } from '@tanstack/match-sorter-utils';
4
5
  import { ReactNode } from 'react';
5
6
  import * as _tanstack_table_core from '@tanstack/table-core';
6
7
 
8
+ declare module '@tanstack/react-table' {
9
+ interface FilterFns {
10
+ fuzzy: FilterFn<unknown>;
11
+ }
12
+ interface FilterMeta {
13
+ itemRank: RankingInfo;
14
+ }
15
+ }
7
16
  interface DataTableProps<T> {
8
17
  children: JSX.Element | JSX.Element[];
9
18
  data: T[];
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var reactTable = require('@tanstack/react-table');
5
5
  var react = require('react');
6
+ var matchSorterUtils = require('@tanstack/match-sorter-utils');
6
7
  var axios = require('axios');
7
8
  var react$1 = require('@chakra-ui/react');
8
9
  var md = require('react-icons/md');
@@ -17,8 +18,20 @@ const TableContext = react.createContext({
17
18
  setGlobalFilter: () => { },
18
19
  });
19
20
 
21
+ // Define a custom fuzzy filter function that will apply ranking info to rows (using match-sorter utils)
22
+ const fuzzyFilter = (row, columnId, value, addMeta) => {
23
+ // Rank the item
24
+ const itemRank = matchSorterUtils.rankItem(row.getValue(columnId), value);
25
+ // Store the itemRank info
26
+ addMeta({
27
+ itemRank,
28
+ });
29
+ // Return if the item should be filtered in/out
30
+ return itemRank.passed;
31
+ };
20
32
  const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, children, }) => {
21
33
  const [columnOrder, setColumnOrder] = react.useState([]);
34
+ const [globalFilter, setGlobalFilter] = react.useState('');
22
35
  const table = reactTable.useReactTable({
23
36
  data: data,
24
37
  columns: columns,
@@ -33,6 +46,7 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
33
46
  },
34
47
  state: {
35
48
  columnOrder,
49
+ globalFilter,
36
50
  },
37
51
  onColumnOrderChange: (state) => {
38
52
  setColumnOrder(state);
@@ -41,6 +55,11 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
41
55
  enableMultiRowSelection: enableMultiRowSelection,
42
56
  enableSubRowSelection: enableSubRowSelection,
43
57
  columnResizeMode: "onChange",
58
+ filterFns: {
59
+ fuzzy: fuzzyFilter, //define as a filter function that can be used in column definitions
60
+ },
61
+ onGlobalFilterChange: setGlobalFilter,
62
+ globalFilterFn: 'fuzzy', //apply fuzzy filter to the global filter (most common use case for fuzzy filter)
44
63
  });
45
64
  react.useEffect(() => {
46
65
  setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
@@ -50,6 +69,8 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
50
69
  refreshData: () => {
51
70
  throw new Error("not implemented");
52
71
  },
72
+ globalFilter: globalFilter,
73
+ setGlobalFilter: setGlobalFilter,
53
74
  }, children: children }));
54
75
  };
55
76
 
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
2
  import { useReactTable, getCoreRowModel, getFilteredRowModel, getSortedRowModel, getPaginationRowModel, flexRender } from '@tanstack/react-table';
3
3
  import { createContext, useState, useEffect, useContext } from 'react';
4
+ import { rankItem } from '@tanstack/match-sorter-utils';
4
5
  import axios from 'axios';
5
6
  import { Button, Box, Text, Input, Popover, Tooltip, PopoverTrigger, IconButton, PopoverContent, PopoverArrow, PopoverBody, Flex, FormControl, Checkbox, Menu, MenuButton, MenuList, MenuItem, Container, Table as Table$1, Grid, Card, CardBody, Tfoot, Tr as Tr$1, Th, Thead, Portal, ButtonGroup, Icon } from '@chakra-ui/react';
6
7
  import { MdFilterAlt, MdArrowUpward, MdArrowDownward, MdOutlineMoveDown, MdOutlineSort, MdPushPin, MdCancel, MdSort, MdFilterListAlt, MdFirstPage, MdArrowBack, MdArrowForward, MdLastPage, MdClear, MdOutlineChecklist } from 'react-icons/md';
@@ -15,8 +16,20 @@ const TableContext = createContext({
15
16
  setGlobalFilter: () => { },
16
17
  });
17
18
 
19
+ // Define a custom fuzzy filter function that will apply ranking info to rows (using match-sorter utils)
20
+ const fuzzyFilter = (row, columnId, value, addMeta) => {
21
+ // Rank the item
22
+ const itemRank = rankItem(row.getValue(columnId), value);
23
+ // Store the itemRank info
24
+ addMeta({
25
+ itemRank,
26
+ });
27
+ // Return if the item should be filtered in/out
28
+ return itemRank.passed;
29
+ };
18
30
  const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSelection = true, enableSubRowSelection = true, children, }) => {
19
31
  const [columnOrder, setColumnOrder] = useState([]);
32
+ const [globalFilter, setGlobalFilter] = useState('');
20
33
  const table = useReactTable({
21
34
  data: data,
22
35
  columns: columns,
@@ -31,6 +44,7 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
31
44
  },
32
45
  state: {
33
46
  columnOrder,
47
+ globalFilter,
34
48
  },
35
49
  onColumnOrderChange: (state) => {
36
50
  setColumnOrder(state);
@@ -39,6 +53,11 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
39
53
  enableMultiRowSelection: enableMultiRowSelection,
40
54
  enableSubRowSelection: enableSubRowSelection,
41
55
  columnResizeMode: "onChange",
56
+ filterFns: {
57
+ fuzzy: fuzzyFilter, //define as a filter function that can be used in column definitions
58
+ },
59
+ onGlobalFilterChange: setGlobalFilter,
60
+ globalFilterFn: 'fuzzy', //apply fuzzy filter to the global filter (most common use case for fuzzy filter)
42
61
  });
43
62
  useEffect(() => {
44
63
  setColumnOrder(table.getAllLeafColumns().map((column) => column.id));
@@ -48,6 +67,8 @@ const DataTable = ({ columns, data, enableRowSelection = true, enableMultiRowSel
48
67
  refreshData: () => {
49
68
  throw new Error("not implemented");
50
69
  },
70
+ globalFilter: globalFilter,
71
+ setGlobalFilter: setGlobalFilter,
51
72
  }, children: children }));
52
73
  };
53
74
 
@@ -1,5 +1,14 @@
1
1
  /// <reference types="react" />
2
- import { ColumnDef } from "@tanstack/react-table";
2
+ import { ColumnDef, FilterFn } from "@tanstack/react-table";
3
+ import { RankingInfo } from '@tanstack/match-sorter-utils';
4
+ declare module '@tanstack/react-table' {
5
+ interface FilterFns {
6
+ fuzzy: FilterFn<unknown>;
7
+ }
8
+ interface FilterMeta {
9
+ itemRank: RankingInfo;
10
+ }
11
+ }
3
12
  export interface DataTableProps<T> {
4
13
  children: JSX.Element | JSX.Element[];
5
14
  data: T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsol-oss/react-datatable5",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -39,6 +39,7 @@
39
39
  "@chakra-ui/react": "^2.8.2",
40
40
  "@emotion/react": "^11.11.4",
41
41
  "@emotion/styled": "^11.11.0",
42
+ "@tanstack/match-sorter-utils": "^8.15.1",
42
43
  "@tanstack/react-table": "^8.16.0",
43
44
  "axios": "^1.6.8",
44
45
  "framer-motion": "^11.0.22",