Skip to content

Commit bb2527e

Browse files
avnunntannerlinsley
authored andcommitted
Added documentation for column accessors (TanStack#82)
1 parent 6d5207e commit bb2527e

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const data = [{
9999

100100
const columns = [{
101101
header: 'Name',
102-
accessor: 'name' // String-based value accessors !
102+
accessor: 'name' // String-based value accessors!
103103
}, {
104104
header: 'Age',
105105
accessor: 'age',
@@ -245,7 +245,7 @@ Or just define them as props
245245
```javascript
246246
[{
247247
// General
248-
accessor: 'propertyName' or Accessor eg. (row) => row.propertyName,
248+
accessor: 'propertyName' // or Accessor eg. (row) => row.propertyName (see "Accessors" section for more details)
249249
id: 'myProperty', // Conditional - A unique ID is required if the accessor is not a string or if you would like to override the column name used in server-side calls
250250
sortable: true,
251251
show: true, // can be used to hide a column
@@ -278,6 +278,28 @@ Or just define them as props
278278
}]
279279
```
280280

281+
## Accessors
282+
Accessors are functions that return the value to populate the row's value for the column.
283+
This lets the render function not have to worry about accessing the correct data, the value is automatically populated in it's props.
284+
285+
If a `string` or `array` is passed the default accessor is used.
286+
The default accessor will parse the input into an array and recursively flatten it.
287+
Any values that contain a dot (`.`) will be split.
288+
Any values that contain bracket (`[]`) will be split.
289+
This array is then used as the path to the value to return.
290+
291+
("$" is the placeholder value that would be returned by the default accessor)
292+
| value | path | data |
293+
|--------------|-----------------|------------------------|
294+
| "a" | ["a"] | {"a": $} |
295+
| "a.b" | ["a", "b"] | {"a": {"b": $}} |
296+
| "a[0]" | ["a", "0"] | {"a": [$]} |
297+
| ["a.b", "c"] | ["a", "b", "c"] | {"a": {"b": {"c": $}}} |
298+
299+
*NOTE*
300+
If your data has a field/key with a dot (`.`) you will need to supply a custom accessor.
301+
302+
281303
## Column Header Groups
282304
To group columns with another header column, just nest your columns in a header column. Header columns utilize the same header properties as regular columns.
283305
```javascript

0 commit comments

Comments
 (0)