constantin-p / cp-react-tree-table

A fast, efficient tree table component for ReactJS.
https://constantin.software/cp-react-tree-table
MIT License
95 stars 27 forks source link

implement `scrollTo(posY)` & `scrollIntoView(node)` #5

Closed constantin-p closed 6 years ago

constantin-p commented 6 years ago

scrollTo(posY: number)

scrollIntoView(node: TreeDataRow, expandAncestors: boolean = true)

scrollTo & scrollIntoView are public methods of TreeDataTable and can be accessed by acquiring a reference to the component.

class DemoApp extends React.Component {
  table: ?TreeDataTable; // 1. reference property

  componentDidMount() {
    if (this.table) {
      // 3. API calls
      this.table.scrollIntoView(objToMatch);
      // OR
      // this.table.scrollTo(posY);
    }
  }

  render () {
    return (
      <TreeDataTable

        ref={elem => {this.table = elem}} // 2. acquiring the reference

        data={DATA}
        height={500}
        rowHeight={30}>
        <TreeDataTable.Column grow={1} renderCell={this.renderColumn} />
      </TreeDataTable>
    );
  }

  renderColumn = (data: any, metadata: RowMetadata, toggleChildren: () => void) => {
    return (
      <div className="cell-wrapper">
        <span>{data}</span>
      </div>
    );
  }
}
constantin-p commented 6 years ago

@pmilla1606 Would like your thoughts on the functionality and if there are use cases not supported by the current implementation.

pmilla1606 commented 6 years ago

@constantin-p this is great! will try it out tonight. let me know when you're thinking of publishing a new version to npm too. thanks for all the hard work!

constantin-p commented 6 years ago

@pmilla1606 I'm gonna wait for your feedback, If everything's OK I'm gonna update the npm version tomorrow.

pmilla1606 commented 6 years ago

@constantin-p just took a look. Looks and works great! Thanks again for the effort.

👍

constantin-p commented 6 years ago

@pmilla1606 version 0.5.0 contains the new functionality