Files
react-table/src/hooks/useSimpleLayout.js
T
Gary MenzelandTanner Linsley 98bee0a4a7 Feature/useSimpleLayout (#1322)
* Install useSimpleLayout and adjust useTable and useRows as required.

* useSimpleLayout integration

* Minor final fix - replace .filter with .forEach

* Used a spread on the path.
2019-04-28 09:53:34 -06:00

38 lines
762 B
JavaScript

export const useSimpleLayout = props => {
const {
hooks: {
columns: columnsHooks,
getHeaderProps,
getCellProps
}
} = props
columnsHooks.push((columns, api) => {
columns.forEach(column => {
column.visible =
typeof column.show === 'function' ? column.show(api) : !!column.show
})
getHeaderProps.push(column => ({
style: {
boxSizing: 'border-box',
width: column.width !== undefined ? `${column.width}px` : 'auto'
}
}))
getCellProps.push(cell => {
return {
style: {
boxSizing: 'border-box',
width: cell.column.width !== undefined ? `${cell.column.width}px` : 'auto'
}
}
})
return columns
})
return props
}