Skip to content

Hiding columns #2692

Answered by amrelhady
skmills asked this question in Q&A
Oct 11, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I don't think there is, couldn't find any Column property for it. I've tried two approaches.

1. Filter out the Column, something like this:

// update state
function hideColumn(column: string) {
    setState({...state, hiddenColumns: [...state.hiddenColumns, column]})
}

// component renders again after state change
const columns = useMemo(() => AllColumns.filter(c => state.hiddenColumns.indexOf(c.key) < 0), state.hiddenColumns)

...

<DataGrid columns={columns} .../>

2. CSS. Not a good solution. But if you want, you can set the cellClass Column property, and then alter the visibility with styles. (display, visibility, width/height, ...). Something along those lines:

Column = {..., cellCl…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@skmills
Comment options

Answer selected by skmills
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants