Skip to content

Commit

Permalink
feat: add support for displaying filters
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Murray <[email protected]>
  • Loading branch information
mikemurray committed Sep 27, 2019
1 parent 03c5ceb commit 9ffd99e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions package/src/components/DataTable/helpers/useDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
* @returns {Object} args
*/
export default function useDataTable({
DefaultColumnFilter,
data: simpleData,
columns,
onFetchData,
Expand All @@ -25,6 +26,7 @@ export default function useDataTable({
const [stateData, setData] = useState([]);
const [pageCount, setPageCount] = useState(0);
const [globalFilter, setGlobalFilter] = useState();
const [shouldShowAdditionalFilters, setShowAdditionalFilters] = useState(false);
const tableState = useTableState({ pageCount: 0, pageSize: defaultPageSize });
const [{ sortBy, filters, pageIndex, pageSize, selectedRows }] = tableState;

Expand All @@ -36,6 +38,14 @@ export default function useDataTable({
data = simpleData;
}

const defaultColumn = React.useMemo(
() => ({
// Let's set up our default Filter UI
Filter: DefaultColumnFilter || (() => null)
}),
[DefaultColumnFilter]
);

const columnsWithCheckboxes = useMemo(() => {
if (isSelectable) {
const hasCheckboxColumn = Boolean(columns.find(({ id }) => id === "selection"));
Expand Down Expand Up @@ -127,6 +137,7 @@ export default function useDataTable({
{
columns: columnsWithCheckboxes,
data,
defaultColumn,
getRowID: (row, index) => `${pageIndex}.${index}`,
state: tableState,
manualFilters: isServerControlled,
Expand All @@ -143,6 +154,8 @@ export default function useDataTable({
return {
...dataTableProps,
isSelectable,
setShowAdditionalFilters,
shouldShowAdditionalFilters,
onGlobalFilterChange: handleGlobalFilterChange
};
}

0 comments on commit 9ffd99e

Please sign in to comment.