diff --git a/examples/sorting-client-side/src/App.js b/examples/sorting-client-side/src/App.js
index e9cfee6..13ec4bd 100644
--- a/examples/sorting-client-side/src/App.js
+++ b/examples/sorting-client-side/src/App.js
@@ -58,26 +58,17 @@ function Table({ columns, data }) {
{headerGroups.map(headerGroup => (
- {headerGroup.headers.map(
- column =>
- console.log(column) || (
- // Add the sorting props to control sorting. For this example
- // we can add them into the header props
-
- )
- )}
+ {headerGroup.headers.map(column => (
+ // Add the sorting props to control sorting. For this example
+ // we can add them into the header props
+
))}
diff --git a/src/filterTypes.js b/src/filterTypes.js
index cfa1ec2..ad785b5 100644
--- a/src/filterTypes.js
+++ b/src/filterTypes.js
@@ -1,12 +1,11 @@
export const text = (rows, id, filterValue) => {
- return rows.filter(row => {
+ rows = rows.filter(row => {
const rowValue = row.values[id]
- return rowValue !== undefined
- ? String(rowValue)
- .toLowerCase()
- .includes(String(filterValue).toLowerCase())
- : true
+ return String(rowValue)
+ .toLowerCase()
+ .includes(String(filterValue).toLowerCase())
})
+ return rows
}
text.autoRemove = val => !val
diff --git a/src/hooks/tests/useTable.test.js b/src/hooks/tests/useTable.test.js
index 9f7b879..2c8841d 100644
--- a/src/hooks/tests/useTable.test.js
+++ b/src/hooks/tests/useTable.test.js
@@ -1,6 +1,5 @@
import '@testing-library/react/cleanup-after-each'
import '@testing-library/jest-dom/extend-expect'
-// NOTE: jest-dom adds handy assertions to Jest and is recommended, but not required
import React from 'react'
import { render } from '@testing-library/react'
diff --git a/src/hooks/useTable.js b/src/hooks/useTable.js
index 839cd80..e34673f 100755
--- a/src/hooks/useTable.js
+++ b/src/hooks/useTable.js
@@ -63,6 +63,7 @@ export const useTable = (props, ...plugins) => {
plugins,
hooks: {
columnsBeforeHeaderGroups: [],
+ columnsBeforeHeaderGroupsDeps: [],
useMain: [],
useColumns: [],
useHeaders: [],
@@ -84,45 +85,57 @@ export const useTable = (props, ...plugins) => {
})
if (debug) console.timeEnd('plugins')
- // Compute columns, headerGroups and headers
- const columnInfo = React.useMemo(
+ if (debug) console.info('buildColumns/headerGroup/headers')
+ // Decorate All the columns
+ let columnTree = React.useMemo(
+ () => decorateColumnTree(userColumns, defaultColumn),
+ [defaultColumn, userColumns]
+ )
+
+ // Get the flat list of all columns
+ let columns = React.useMemo(() => flattenBy(columnTree, 'columns'), [
+ columnTree,
+ ])
+
+ // Allow hooks to decorate columns (and trigger this memoization via deps)
+ columns = React.useMemo(
() => {
- if (debug) console.info('buildColumns/headerGroup/headers')
- // Decorate All the columns
- let columnTree = decorateColumnTree(userColumns, defaultColumn)
-
- // Get the flat list of all columns
- let columns = flattenBy(columnTree, 'columns')
-
- // Allow hooks to decorate columns
if (debug) console.time('hooks.columnsBeforeHeaderGroups')
- columns = applyHooks(
+ const newColumns = applyHooks(
instanceRef.current.hooks.columnsBeforeHeaderGroups,
columns,
instanceRef.current
)
if (debug) console.timeEnd('hooks.columnsBeforeHeaderGroups')
-
- // Make the headerGroups
- const headerGroups = makeHeaderGroups(
- columns,
- findMaxDepth(columnTree),
- defaultColumn
- )
-
- const headers = flattenBy(headerGroups, 'headers')
-
- return {
- columns,
- headerGroups,
- headers,
- }
+ return newColumns
},
- [debug, defaultColumn, userColumns]
+ [
+ columns,
+ debug,
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ ...applyHooks(
+ instanceRef.current.hooks.columnsBeforeHeaderGroupsDeps,
+ [],
+ instanceRef.current
+ ),
+ ]
)
- // Place the columns, headerGroups and headers on the api
- Object.assign(instanceRef.current, columnInfo)
+ // Make the headerGroups
+ const headerGroups = React.useMemo(
+ () => makeHeaderGroups(columns, findMaxDepth(columnTree), defaultColumn),
+ [columnTree, columns, defaultColumn]
+ )
+
+ const headers = React.useMemo(() => flattenBy(headerGroups, 'headers'), [
+ headerGroups,
+ ])
+
+ Object.assign(instanceRef.current, {
+ columns,
+ headerGroups,
+ headers,
+ })
// Access the row model
instanceRef.current.rows = React.useMemo(
diff --git a/src/plugin-hooks/tests/__snapshots__/useFilters.test.js.snap b/src/plugin-hooks/tests/__snapshots__/useFilters.test.js.snap
index 792cada..9a77135 100644
--- a/src/plugin-hooks/tests/__snapshots__/useFilters.test.js.snap
+++ b/src/plugin-hooks/tests/__snapshots__/useFilters.test.js.snap
@@ -1,11 +1,203 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`renders a sortable table 1`] = `
+exports[`renders a filterable table 1`] = `
"Snapshot Diff:
-Compared values have no visual difference."
+- First value
++ Second value
+
+@@ -37,11 +37,11 @@
+ colspan=\\"1\\"
+ >
+ Last Name
+
+
+
+
+ progress: 50
+-
+-
+-
+-
+- firstName: derek
+-
+-
+- lastName: perkins
+-
+-
+- age: 40
+-
+-
+- visits: 40
+-
+-
+- status: Single
+-
+-
+- progress: 80
+-
+-
+-
+-
+- firstName: joe
+-
+-
+- lastName: bergevin
+-
+-
+- age: 45
+-
+-
+- visits: 20
+-
+-
+- status: Complicated
+-
+-
+- progress: 10
+
+
+
"
`;
-exports[`renders a sortable table 2`] = `
+exports[`renders a filterable table 2`] = `
"Snapshot Diff:
-Compared values have no visual difference."
+- First value
++ Second value
+
+@@ -37,11 +37,11 @@
+ colspan=\\"1\\"
+ >
+ Last Name
+
+
+
+
+- firstName: tanner
++ firstName: derek
+
+
+- lastName: linsley
++ lastName: perkins
+
+
+- age: 29
++ age: 40
+
+
+- visits: 100
++ visits: 40
+
+
+- status: In Relationship
++ status: Single
+
+
+- progress: 50
++ progress: 80
+
+
+
+
+- firstName: jaylen
++ firstName: joe
+
+
+- lastName: linsley
++ lastName: bergevin
+
+
+- age: 26
++ age: 45
+
+
+- visits: 99
++ visits: 20
+
+
+- status: In Relationship
++ status: Complicated
+
+
+- progress: 70
++ progress: 10
+
+
+
+
+ "
`;
diff --git a/src/plugin-hooks/tests/__snapshots__/useGroupBy.test.js.snap b/src/plugin-hooks/tests/__snapshots__/useGroupBy.test.js.snap
new file mode 100644
index 0000000..416f162
--- /dev/null
+++ b/src/plugin-hooks/tests/__snapshots__/useGroupBy.test.js.snap
@@ -0,0 +1,371 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`renders a filterable table 1`] = `
+"Snapshot Diff:
+- First value
++ Second value
+
+@@ -29,13 +29,13 @@
+
+- 👊
++ 🛑
+
+- First Name
++ Last Name
+
+
+@@ -44,11 +44,11 @@
+ style=\\"cursor: pointer;\\"
+ title=\\"Toggle GroupBy\\"
+ >
+ 👊
+
+- Last Name
++ First Name
+