Comments (10)
@BrettStatman without seeing code or knowing what is different in your situation from the examples, it's hard to tell.
Some ideas:
- Try setting a background color on the cells if there isn't one already
- Try manually triggering a window resize event after the component is mounted
- Check the examples and make sure they're being followed precisely
from react-sticky-table.
Tried those suggestions to no avail.
Here's the implementation:
Table Component:
import { StickyTable, Row, Cell } from 'react-sticky-table';
import 'react-sticky-table/dist/react-sticky-table.css';
class Table extends React.Component {
renderHeader() {
const { columns } = this.props;
const headerCells = columns.map(({ title, minWidth }) => (
<Cell style={{ minWidth }}>{title}</Cell>
));
return (
<Row>
{headerCells}
</Row>
);
}
renderRows() {
const { data, columns } = this.props;
const rows = [];
// create a row for each data item
for (let i = 0, numRows = data.length; i < numRows; i += 1) {
const rowData = data[i];
const cells = [];
// create cells for each column in the row
for (let j = 0, numColumns = columns.length; j < numColumns; j += 1) {
const { key } = columns[j];
const cellData = rowData[key];
cells.push(<Cell>{cellData}</Cell>);
}
rows.push(<Row>{cells}</Row>);
}
return rows;
}
render() {
return (
<div style={{ width: '100%', height: '150px', background: '#FFFFFF' }}>
<StickyTable stickyColumnCount={0}>
{this.renderHeader()}
{this.renderRows()}
</StickyTable>
</div>
);
}
}
export default Table;
Usage:
const data = [
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
{
name: 'Test Name',
status: 'Test Status',
something: 'Test Something',
other: 'Other',
},
];
const columns = [
{
title: 'Name',
key: 'name',
minWidth: 250,
},
{
title: 'Status',
key: 'status',
minWidth: 225,
},
{
title: 'Something',
key: 'something',
minWidth: 250,
},
{
title: 'Other',
key: 'other',
minWidth: 100,
},
];
<div style={{ width: 500 }}>
<Table data={data} columns={columns} />
</div>
from react-sticky-table.
@BrettStatman Try setting a height on the wrapper div. Let me know if that does anything.
from react-sticky-table.
Already have a height set on a wrapper around <StickyTable>
. Added a height on the outermost div but same result.
from react-sticky-table.
@BrettStatman Ah yeah my bad. I'm not really sure. Maybe try triggering a window resize inside a setTimeout with a few hundred ms delay?
Luckily, since you only need a sticky header, there should be a number of other react component solutions people have made for that if you can't get this one to work.
from react-sticky-table.
I do need to use the fixed column as well.
One major difference I noticed is that the parent that is scrolling outside of the table is a flex
container. When that is no longer the case, the problem is fixed. Any ideas for getting this to work with a dynamic height flex parent?
from react-sticky-table.
@BrettStatman are you saying you need to be able to put the sticky table inside a container with display: flex
? I haven't played around with that scenario, but if you've got it working without using flex, you can probably achieve the layout you're going for some other way. I understand that is not ideal...
One thing that might help is adding an additional wrapper that is display block and has a fixed height/width, and is a child of the flex
cell element.
<div class="display-flex">
<div class="display-flex-cell">
<div class="display-block" width="100" height="100">
<StickyTable/>
</div>
</div>
</div>
from react-sticky-table.
@BrettStatman Did you have any luck with this? v2 was just published it's possible it will fix your issue. Closing for now.
from react-sticky-table.
@maxhudson - Wasn't able to get this working. Switched to a different solution for now!
from react-sticky-table.
@BrettStatman Ok - sorry about that. Out of curiosity, what are you using now? Maybe we can improve our solution if we see it.
from react-sticky-table.
Related Issues (20)
- Not able to customize table cell width HOT 9
- Remove `/docs` folder from NPM package HOT 1
- Scrolling issue when changing leftStickyColumnCount to 1 HOT 4
- Where can I read change log? HOT 1
- Prevent overscroll/bounce in iOS MobileSafari HOT 1
- Can't apply styling to rows HOT 2
- Full width table HOT 3
- Ability to Resize columns using mouse HOT 1
- Alternate Color Rows HOT 1
- Sticky headers don't work if height is set as percetages HOT 2
- Unable to add row color on hover HOT 1
- Update to be used along with react 18 HOT 1
- Cannot apply styles to header row HOT 1
- the header of table cover the dropdown list HOT 4
- Issues when having more than 1 sticky row/column HOT 3
- IE11 support HOT 2
- seeking examples HOT 5
- storybook show source code HOT 3
- <table> support HOT 1
- Does react-sticky-table work with <table> too ? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-sticky-table.