@jasperoosthoek/react-toolbox 0.6.8 → 0.7.0
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/package.json
CHANGED
|
@@ -78,7 +78,7 @@ export type DataTableProps<D extends any[]> = {
|
|
|
78
78
|
columns: DataTableColumn<D[number]>[];
|
|
79
79
|
rowsPerPage?: number | null;
|
|
80
80
|
rowsPerPageOptions?: RowsPerPageOptions;
|
|
81
|
-
filterColumn?: ((row: D[number]) => string) | string;
|
|
81
|
+
filterColumn?: (keyof D) | ((row: D[number]) => string) | ((keyof D) | ((row: D[number]) => string))[];
|
|
82
82
|
orderByDefault?: ((row: D[number]) => number) | string | null;
|
|
83
83
|
orderByDefaultDirection?: OrderByDirection;
|
|
84
84
|
onMove?: OnMove<D[number]>;
|
|
@@ -126,16 +126,24 @@ export const DataTable = <D extends any[]>({
|
|
|
126
126
|
const [rowsPerPage, setRowsPerPage] = useState(rowsPerPageDefault);
|
|
127
127
|
const [page, setPage] = useState(0);
|
|
128
128
|
let data = allData && (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
Object.values(allData).filter(row =>
|
|
130
|
+
filterColumn && filterText
|
|
131
|
+
? (
|
|
132
|
+
typeof filterColumn === 'function'
|
|
133
|
+
? filterColumn(row)
|
|
134
|
+
: Array.isArray(filterColumn)
|
|
135
|
+
? filterColumn.reduce((acc, col) => {
|
|
136
|
+
if (typeof col === 'function') {
|
|
137
|
+
return acc + ' ' + col(row);
|
|
138
|
+
} else if (typeof row[col] !== 'undefined') {
|
|
139
|
+
return acc + ' ' + row[col];
|
|
140
|
+
}
|
|
141
|
+
return acc;
|
|
142
|
+
}, '')
|
|
143
|
+
: row[filterColumn]
|
|
144
|
+
).toString().match(new RegExp(`${filterText}`, 'i'))
|
|
145
|
+
: true
|
|
146
|
+
)
|
|
139
147
|
);
|
|
140
148
|
|
|
141
149
|
const pagesCount = (data && rowsPerPage && Math.ceil(data.length / rowsPerPage));
|