Reputation: 2561
Could we fix a column when we get a horizontal column with smaller pages?
For example could we fix the column firstName
in this example.
Cheers!!
Upvotes: 11
Views: 40702
Reputation: 880
Try below things, it might help:
In React, CSS part in component itself:
fix: {
position: 'sticky',
right: 0,
padding: '11px 16px',
boxShadow: '0px 4px 4px 0px #999',
},
fixColumn: {
position: 'sticky',
right: 0,
},
In my case of - Material-UI DataTable
<MuiTable component="table" {...getProps()}>
<TableHead>
{headerGroups.map(prop => (
<TableRow {...prop.getAllHeaderProps()}>
{prop.headers.map((column, index) => {
const fixColIndex = column.id === 'column_id_need_to_fix' ? index : '';);
const fixHeaderProps = column.getHeaderProps({
className: clsx({ [classes.fixColumn]: fixColIndex }, column.className),
});return (
<TableCell {...fixHeaderProps}></TableCell>
);
})}
</TableRow>
))}
</TableHead>
Under TableBody
const Props = props.getProps({
className: clsx(
{
[classes.fix]: props.column.id === fixColumnId,
},
),
});
return (
<TableCell {...Props}>
{prop.render('Cell')}
</TableCell>
);
Upvotes: 1
Reputation: 317
without using react-table or any npm dependencies fixed column can be achieved only via css tricks with in react app.
Find the full code Here
Step 1 : divide the dataset of fixed and scrollable columns
Step 2 : place two tables side by side in such a way that it looks as single table
Step 3 : Wrap both with a single div and use a fixed width, give fixed width or responsive width for second one and make overflow-x: scroll; so that it keeps scrolling horizontally,while first tables columns will not be scrollable
Upvotes: 6
Reputation: 12746
Since v7 of react-table
was released recently and it's a complete rewrite, react-table-hoc-fixed-columns is not compatible with it. If you are using version <7 then see @Alex's answer above.
For react-table
v7, you can use react-table-sticky by the same author.
Upvotes: 5
Reputation: 360
react-table does not support fixed columns, issue is opened Sticky columns. But there is already implemented workaround, you can find sources github or npm package (link taken from thread Sticky columns). Online Demo. Thanks to GuillaumeJasmin.
Upvotes: 6