Skip to content

Commit

Permalink
add fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrylo Hudym-Levkovych authored and Kyrylo Hudym-Levkovych committed Sep 6, 2023
1 parent 8c6e23d commit 45cfc89
Showing 1 changed file with 104 additions and 112 deletions.
216 changes: 104 additions & 112 deletions src/DataTable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,97 +53,98 @@ or a filter component can be defined on the column. See <a href="https://react-t
for more information.

```jsx live
<DataTable
isPaginated
isSelectable
initialState={{
pageSize: 2,
}}
isFilterable
isSortable
defaultColumnValues={{ Filter: TextFilter }}
itemCount={7}
data={[
{
name: 'Lil Bub',
color: 'brown tabby',
famous_for: 'weird tongue',
},
{
name: 'Grumpy Cat',
color: 'siamese',
famous_for: 'serving moods',
},
{
name: 'Smoothie',
color: 'orange tabby',
famous_for: 'modeling',
},
{
name: 'Maru',
color: 'brown tabby',
famous_for: 'being a lovable oaf',
},
{
name: 'Keyboard Cat',
color: 'orange tabby',
famous_for: 'piano virtuoso',
},
{
name: 'Long Cat',
color: 'russian white',
famous_for:
'being loooooooooooooooooooooooooooooooooooooooooooooooooooooong',
},
{
name: 'Zeno',
color: 'brown tabby',
famous_for: 'getting halfway there'
},
]}
columns={[
{
Header: 'Name',
accessor: 'name',
() => {
const data = useMemo(() => [
{
name: 'Lil Bub',
color: 'brown tabby',
famous_for: 'weird tongue',
},
{
name: 'Grumpy Cat',
color: 'siamese',
famous_for: 'serving moods',
},
{
name: 'Smoothie',
color: 'orange tabby',
famous_for: 'modeling',
},
{
name: 'Maru',
color: 'brown tabby',
famous_for: 'being a lovable oaf',
},
{
name: 'Keyboard Cat',
color: 'orange tabby',
famous_for: 'piano virtuoso',
},
{
name: 'Long Cat',
color: 'russian white',
famous_for:
'being loooooooooooooooooooooooooooooooooooooooooooooooooooooong',
},
{
name: 'Zeno',
color: 'brown tabby',
famous_for: 'getting halfway there'
},
], [])

},
{
Header: 'Famous For',
accessor: 'famous_for',
},
{
Header: 'Coat Color',
accessor: 'color',
Filter: CheckboxFilter,
filter: 'includesValue',
filterChoices: [{
name: 'russian white',
number: 1,
value: 'russian white',
},
const reducedChoices = data.reduce((acc, currentObject) => {
const { color } = currentObject;
if (color in acc) {
acc[color].number += 1;
} else {
acc[color] = {
name: color,
number: 1,
value: color,
};
}
return acc;
}, {});

return (
<DataTable
isPaginated
isSelectable
initialState={{
pageSize: 2,
}}
isFilterable
isSortable
defaultColumnValues={{ Filter: TextFilter }}
itemCount={data.length}
data={data}
columns={[
{
name: 'orange tabby',
number: 2,
value: 'orange tabby',
Header: 'Name',
accessor: 'name',

},
{
name: 'brown tabby',
number: 3,
value: 'brown tabby',
Header: 'Famous For',
accessor: 'famous_for',
},
{
name: 'siamese',
number: 1,
value: 'siamese',
}]
},
]}
>
<DataTable.TableControlBar />
<DataTable.Table />
<DataTable.EmptyTable content="No results found" />
<DataTable.TableFooter />
</DataTable>
Header: 'Coat Color',
accessor: 'color',
Filter: CheckboxFilter,
filter: 'includesValue',
filterChoices: Object.values(reducedChoices),
},
]}
>
<DataTable.TableControlBar />
<DataTable.Table />
<DataTable.EmptyTable content="No results found" />
<DataTable.TableFooter />
</DataTable>
);
}
```

## Backend filtering and sorting
Expand Down Expand Up @@ -360,19 +361,6 @@ See ``dataViewToggleOptions`` props documentation for all supported props.
famous_for: 'modeling',
},
], [])
const reducedChoices = data.reduce((acc, currentObject) => {
const { color } = currentObject;
if (color in acc) {
color.number += 1;
} else {
acc[color] = {
name: color,
number: 1,
value: color,
};
}
return acc;
}, {});

return (
<DataTable
Expand Down Expand Up @@ -401,7 +389,21 @@ See ``dataViewToggleOptions`` props documentation for all supported props.
accessor: 'color',
Filter: CheckboxFilter,
filter: 'includesValue',
filterChoices: Object.values(reducedChoices),
filterChoices: [{
name: 'orange tabby',
number: 1,
value: 'orange tabby',
},
{
name: 'brown tabby',
number: 1,
value: 'brown tabby',
},
{
name: 'siamese',
number: 1,
value: 'siamese',
}],
},
]}
>
Expand Down Expand Up @@ -468,18 +470,13 @@ See ``dataViewToggleOptions`` props documentation for all supported props.
Filter: CheckboxFilter,
filter: 'includesValue',
filterChoices: [{
name: 'russian white',
number: 1,
value: 'russian white',
},
{
name: 'orange tabby',
number: 2,
number: 1,
value: 'orange tabby',
},
{
name: 'brown tabby',
number: 3,
number: 1,
value: 'brown tabby',
},
{
Expand Down Expand Up @@ -1275,18 +1272,13 @@ For a more desktop friendly view, you can move filters into a sidebar by providi
Filter: CheckboxFilter,
filter: 'includesValue',
filterChoices: [{
name: 'russian white',
number: 1,
value: 'russian white',
},
{
name: 'orange tabby',
number: 2,
value: 'orange tabby',
},
{
name: 'brown tabby',
number: 3,
number: 2,
value: 'brown tabby',
},
{
Expand Down

0 comments on commit 45cfc89

Please sign in to comment.