Skip to content

Commit

Permalink
docs: document mapRow ExternalField API
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Mar 26, 2024
1 parent dbe66d1 commit 9b794d9
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const config = {
| [`initialFilters`](#initialfilters) | `{ "rating": 1 }` | Object | - |
| [`initialQuery`](#initialquery) | `initialQuery: "Hello, world"` | String | - |
| [`mapProp()`](#mappropitem) | `mapProp: async ({ title }) => title` | Function | - |
| [`mapRow()`](#mappropitem) | `mapRow: async ({ title }) => title` | Function | - |
| [`placeholder`](#placeholder) | `placeholder: "Select content"` | String | - |
| [`showSearch`](#showsearch) | `showSearch: true` | Boolean | - |

Expand Down Expand Up @@ -435,6 +436,56 @@ const config = {
}}
/>

### `mapRow(item)`

Modify the shape of the item before rendering it in the table. This will not affect the selected data.

```tsx {13} copy
const config = {
components: {
Example: {
fields: {
data: {
type: "external",
fetchList: async () => {
return [
{ title: "Hello, world", description: "Lorem ipsum 1" },
{ title: "Goodbye, world", description: "Lorem ipsum 2" },
];
},
mapRow: (item) => ({ ...item, title: item.title.toUpperCase() }),
},
},
render: ({ data }) => {
return <p>{data || "No data selected"}</p>;
},
// ...
},
},
};
```

<ConfigPreview
label="Example"
componentConfig={{
fields: {
data: {
type: "external",
fetchList: async () => {
return [
{ title: "Hello, world", description: "Lorem ipsum 1" },
{ title: "Goodbye, world", description: "Lorem ipsum 2" },
];
},
mapRow: (item) => ({ ...item, title: item.title.toUpperCase() }),
},
},
render: ({ data }) => {
return <p>{data?.title || "No data selected"}</p>;
},
}}
/>

### `placeholder`

Set the placeholder text when no item is selected.
Expand Down

0 comments on commit 9b794d9

Please sign in to comment.