Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feature) VirtualTable: disable resizing columns option #193

Merged
merged 3 commits into from
Aug 18, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ export const columnHeaderRenderer = (
updateTableState,
) => {
const {
dataKey, minWidth = 30, width, label,
dataKey,
minWidth = 30,
width,
label,
columnData: { disableDrag = false } = {},
} = columnParams
const isDraggable = !!label
const isDraggable = !!label && !disableDrag

const onStop = (e, { x }) => {
e.stopPropagation()
Expand Down
32 changes: 26 additions & 6 deletions packages/core/src/components/ui/VirtualTable/VirtualTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
Table,
Column,
defaultTableRowRenderer,
defaultTableHeaderRenderer,
} from 'react-virtualized'

import * as Classes from '../../../common/classes'
Expand Down Expand Up @@ -43,6 +44,7 @@ const VirtualTable = forwardRef((props, ref) => {
onScrollToBottom,
tableState,
updateTableState,
disableColumnsResizing,
...rest
} = props

Expand Down Expand Up @@ -120,12 +122,15 @@ const VirtualTable = forwardRef((props, ref) => {
}

const columnHeaderRenderer = useCallback(
(columnParams) => _columnHeaderRenderer(
columnParams,
setColumnsWidthState,
updateTableState,
),
[updateTableState],
(columnParams) => (
disableColumnsResizing
? defaultTableHeaderRenderer(columnParams)
: _columnHeaderRenderer(
columnParams,
setColumnsWidthState,
updateTableState,
)),
[updateTableState, disableColumnsResizing],
)

return (
Expand Down Expand Up @@ -220,6 +225,16 @@ VirtualTable.propTypes = {
* ClassName of column's header
*/
headerClassName: PropTypes.string,
/**
* Additional data passed to this column's cellDataGetter.
* Use this object to relay action-creators or relational data.
*/
columnData: PropTypes.shape({
/**
* If true, the current column width can't be changed by dragging
*/
disableDrag: PropTypes.bool,
}),
}),
), // eslint-disable-line
/**
Expand Down Expand Up @@ -294,6 +309,10 @@ VirtualTable.propTypes = {
* Callback, which updates an external state of the table
*/
updateTableState: PropTypes.func,
/**
* If true, drag and drop column resizing is disabled for the entire table
*/
disableColumnsResizing: PropTypes.bool,
}

VirtualTable.defaultProps = {
Expand All @@ -316,6 +335,7 @@ VirtualTable.defaultProps = {
onScrollToBottom: () => {},
tableState: {},
updateTableState: () => {},
disableColumnsResizing: false,
}

export default memo(VirtualTable)
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { showTemplateStory, getDefaultMetadata } from '../../../../../../storybook/.storybook/helper'
import {
showTemplateStory,
getDefaultMetadata,
} from '../../../../../../storybook/.storybook/helper'
import VirtualTable from '../VirtualTable'
import { columns, data } from './VirtualTable.stories_data'

export default getDefaultMetadata(VirtualTable, 'Components/ui/VirtualTable', {}, false)
export default getDefaultMetadata(
VirtualTable,
'Components/ui/VirtualTable',
{},
false,
)

const props = {
data,
Expand All @@ -12,3 +20,7 @@ const props = {
}

export const basic = showTemplateStory(VirtualTable, props)
export const fixedColumnsWidth = showTemplateStory(VirtualTable, {
...props,
disableColumnsResizing: true,
})
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@ export const columns = [{
<p>X</p>
),
disableSort: true,
columnData: {
disableDrag: true,
},
}]
Loading