Skip to content

Commit 13401f4

Browse files
committed
update
1 parent 4aacbd0 commit 13401f4

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const columns = [
112112
id: 3,
113113
field: 'last_visited',
114114
label: 'Last Visited',
115-
sort: ({a, b, isAscending}) => {
115+
sort: ({ a, b, isAscending }) => {
116116
let aa = a.split('/').reverse().join(),
117117
bb = b.split('/').reverse().join();
118118
return aa < bb ? isAscending ? -1 : 1 : (aa > bb ? isAscending ? 1 : -1 : 0);
@@ -122,7 +122,7 @@ const columns = [
122122
id: 4,
123123
field: 'test',
124124
label: 'Score',
125-
getValue: ({value, column}) => value.x + value.y
125+
getValue: ({ value }) => value.x + value.y
126126
}
127127
];
128128

@@ -275,7 +275,7 @@ Each column (except for '[checkbox](#checkbox-column)' column) has support for t
275275
className: '',
276276
pinned: false,
277277
width: '200px',
278-
getValue: ({value, column}) => value,
278+
getValue: ({ tableManager, value, column, rowData }) => value,
279279
setValue: ({ value, data, setRow, column }) => { setRow({ ...data, [column.field]: value}) },
280280
minResizeWidth: 70,
281281
maxResizeWidth: null,
@@ -353,7 +353,9 @@ Each row should have a unique identifier field, which by default is `id`, but it
353353
}
354354
```
355355

356-
**Note:** If a property value is not of type string, you'll have to use the `getValue` function on the column in order to extract the desired value.
356+
**Note:** If a property value is not of type string, or in cases you don't specify a field for the column, you'll have to use the `getValue` function on the column in order to extract the desired value.
357+
358+
**Signature**: getValue: ({ tableManager, value, column, rowData }) => string
357359

358360
**Example:**
359361

@@ -363,7 +365,7 @@ Let's say the field's value for a cell is an object:
363365

364366
Its `getValue` function for displaying the first and last name as a full name, would be:
365367

366-
`getValue: ({value, column}) => value.firstName + ' ' + value.lastName`
368+
`getValue: ({ value }) => value.firstName + ' ' + value.lastName`
367369

368370
The returned value will be used for searching, sorting etc...
369371

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nadavshaar/react-grid-table",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "A modular table, based on a CSS grid layout, optimized for customization.",
55
"author": "Nadav Shaar",
66
"license": "MIT",

src/hooks/useSearch.jsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,25 @@ const useSearch = (props, tableManager) => {
4242
Object.keys(item).some((key) => {
4343
var cols = columns.filter(
4444
(column) =>
45-
column.searchable &&
46-
(!column.field || column.field === key)
45+
column.searchable && column.field === key
4746
);
47+
4848
let isValid = false;
4949

50-
if (cols.length) {
51-
for (let index = 0; index < cols.length; index++) {
52-
const currentColumn = cols[index];
53-
const value = currentColumn.getValue({
54-
tableManager,
55-
value: item[key],
56-
column: currentColumn,
57-
rowData: item,
58-
});
59-
isValid = currentColumn.search({
60-
value: value?.toString() || "",
61-
searchText: searchApi.validSearchText,
62-
});
50+
for (let index = 0; index < cols.length; index++) {
51+
const currentColumn = cols[index];
52+
const value = currentColumn.getValue({
53+
tableManager,
54+
value: item[key],
55+
column: currentColumn,
56+
rowData: item,
57+
});
58+
isValid = currentColumn.search({
59+
value: value?.toString() || "",
60+
searchText: searchApi.validSearchText,
61+
});
6362

64-
if (isValid) break;
65-
}
63+
if (isValid) break;
6664
}
6765

6866
return isValid;

0 commit comments

Comments
 (0)