Git Product home page Git Product logo

Comments (10)

maxhudson avatar maxhudson commented on August 11, 2024

@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.

BrettStatman avatar BrettStatman commented on August 11, 2024

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.

maxhudson avatar maxhudson commented on August 11, 2024

@BrettStatman Try setting a height on the wrapper div. Let me know if that does anything.

from react-sticky-table.

BrettStatman avatar BrettStatman commented on August 11, 2024

Already have a height set on a wrapper around <StickyTable>. Added a height on the outermost div but same result.

from react-sticky-table.

maxhudson avatar maxhudson commented on August 11, 2024

@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.

BrettStatman avatar BrettStatman commented on August 11, 2024

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.

maxhudson avatar maxhudson commented on August 11, 2024

@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.

maxhudson avatar maxhudson commented on August 11, 2024

@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.

BrettStatman avatar BrettStatman commented on August 11, 2024

@maxhudson - Wasn't able to get this working. Switched to a different solution for now!

from react-sticky-table.

maxhudson avatar maxhudson commented on August 11, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.