Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/utils/columnUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
const offset = 1000;

/** Gets a column properties object from an array of columnNames
Expand All @@ -7,7 +8,7 @@ function getColumnPropertiesFromColumnArray(columnProperties, columns) {
return columns.reduce((previous, current, i) => {
previous[current] = { id: current, order: offset + i };
return previous;
},
},
columnProperties);
}

Expand All @@ -23,7 +24,7 @@ export function getColumnProperties(rowProperties, allColumns=[]) {
// Working against an array of columnProperties
if (Array.isArray(children)) {
// build one object that contains all of the column properties keyed by id
children.reduce((previous, current, i) => {
_.reduce(_.flatten(children),(previous, current, i) => {
if (current) {
previous[current.props.id] = {order: offset + i, ...current.props};
}
Expand All @@ -39,5 +40,5 @@ export function getColumnProperties(rowProperties, allColumns=[]) {
getColumnPropertiesFromColumnArray(columnProperties, allColumns);
}

return columnProperties;
return columnProperties;
}
17 changes: 16 additions & 1 deletion stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,21 @@ storiesOf('Griddle main', module)
</div>
)
})
.add("with filterable set by array of <ColumnDefinition />", () => {
const ids = ["name", "city", "state"];
return (
<div>
<small>Name is not filterable</small>
<Griddle data={fakeData} plugins={[LocalPlugin]}>
<RowDefinition>
{ids.map(id => (
<ColumnDefinition id={id} filterable />
))}
</RowDefinition>
</Griddle>
</div>
);
})
.add('with local and sort set', () => {
const sortProperties = [
{ id: 'name', sortAscending: true }
Expand Down Expand Up @@ -1768,4 +1783,4 @@ storiesOf('TypeScript', module)
</RowDefinition>
</Griddle>
);
})
})