Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Allow specifying table rows in custom components #196

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

glittershark
Copy link
Owner

This is the implementation side of the failing-test PR that @growlsworth originally submitted as #166

@glittershark
Copy link
Owner Author

Further commentary: Because we're doing a render ourselves of the sub-component as a means of parsing out its child components, that sub-component's componentDidMount() will never be called - and in fact its entire lifecycle will be completely discarded after the initial render of the Reactable.Table. That's far from perfect - it'd probably be possible to do the processing to pull the data out of the row or cell and then encode that as part of the __reactableMeta property that we're already saving on the individual components

@trshafer
Copy link

This is boss. Just gave a it a quick look. I'll give it a shot in one of my projects and let you know. Also you don't need to keep the original implementation spike ;)

@glittershark glittershark force-pushed the tr-custom-components branch 2 times, most recently from 4abe39c to 1eb6eb9 Compare October 2, 2015 01:21
@glittershark
Copy link
Owner Author

for posterity, and as a note to myself, the commit that you commented on and then I force-pushed away: 4abe39c

@glittershark
Copy link
Owner Author

@growlsworth I think 1f02dbd should allow passing through child context, do you mind taking a look?

@trshafer
Copy link

trshafer commented Oct 2, 2015

In the parent, which holds the Table, this.context returns {router:…}, and in the child, which is the Tr, this.context still returns undefined.

@trshafer
Copy link

trshafer commented Oct 3, 2015

I'm looking at your context test. Thanks for adding that. And that looks good. I must be doing something weird. I'll check back again.

@trshafer
Copy link

trshafer commented Oct 3, 2015

Ok. I got the test example to pass in my machine. FYI, the lib wasn't updated, which made requiring reactable not load the most up to date version. But I'm still having difficulty with react-router. Will see if I can make a breaking test outside my app.

@trshafer
Copy link

trshafer commented Oct 3, 2015

Ok I got it to fail. The issue is in the child's child's context. :(

Drop this bad boy in tmp/:

<!DOCTYPE html>
<html>
<head>
  <title>Reactable Context Text</title>
  <script type="text/javascript" src="../node_modules/react/dist/react.js"></script>
  <script type="text/javascript" src="../build/reactable.js"></script>
  <script type="text/javascript" src="../node_modules/grunt-babel/node_modules/babel-core/browser.js"></script>
</head>
<body>
<div id="wrapper"></div>

<script type="text/babel">

  let SubItem = React.createClass({
      displayName: 'SubItem',
      contextTypes: { test: React.PropTypes.string },
      render: function(){
          let text;
          if (this.context)
            text = this.context.test || 'no context.test';
          else
            text = 'no context';
          return (
            <div>
              {text}
            </div>
          );
      }
  });

  let RowComponent = React.createClass({
      displayName: 'CustomComponent',
      contextTypes: { test: React.PropTypes.string },
      childContextTypes: { test: React.PropTypes.string },
      getChildContext: function() {
          return { test: 'sub-test' };
      },

      render: function(){
          return (
            <Reactable.Tr>
                <Reactable.Td column="Name">{this.props.name || ''}</Reactable.Td>
                <Reactable.Td column="Test">{this.context.test || ''}</Reactable.Td>
                <Reactable.Td column="SubItem"><SubItem /></Reactable.Td>
            </Reactable.Tr>
          );
      }
  });

  let TableComponent = React.createClass({
      displayName: 'TableComponent',
      childContextTypes: { test: React.PropTypes.string },
      getChildContext: function() {
          return { test: 'foobar' };
      },
      render: function() {
          return (
              <Reactable.Table className="table" id="table">
                  <RowComponent name='Griffin Smith' />
                  <RowComponent name='Lee Salminen' />
              </Reactable.Table>
          );
      }
  });

  React.render(<TableComponent/>, document.getElementById('wrapper'));
</script>

</body>
</html>

@glittershark
Copy link
Owner Author

I'm gonna see what I can do about adding a Travis check to make sure build/ and lib/ are up-to-date 👀

@glittershark
Copy link
Owner Author

Thanks for the failing case, too! will check it out

trshafer and others added 5 commits October 3, 2015 10:27
Since react will not render child components until the parent component
is rendered (exploratory hypotheis) We need to render the custom
component first and then access the component.  This uses a Component
function of getData().  The getData function could/should be fast
because after the render function all the data could be available via
props or state

I have not tested this with updating data from the custom component.  Or
if the custom component internally changes the data and they table needs
to resort.
Use the structure returned by `react.createElement` to do a render of
any child components with unrecognized types, and extract the data out
of them if they themselves return a `<Tr>`
When instantiating child components in order to render them, also pass
through the props given when creating the child component.
if ([_tfoot.Tfoot, _thead.Thead, _tr.Tr].indexOf(child.type) >= 0) {
reactableDescendant = child;
} else {
reactableDescendant = new child.type(child.props, child._context).render();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works in react 0.14.

@educastellano
Copy link
Contributor

what's the status of this branch? Can it be merged to master? :)

@alfredoreduarte
Copy link

I wish I could help with this, just realised I need it as well. Can you guys do the merge? Pretty plz 😀

@singpolyma
Copy link

that sub-component's componentDidMount() will never be called

Could we just call it? Would be great to solve #156

@zacharyz
Copy link

Hello from the future! Would love for this to be included.

@paddotk
Copy link

paddotk commented Oct 31, 2016

Is the merge conflict resolved? I still have the same problem.

@revett
Copy link

revett commented Jan 20, 2017

Can this be merged?

@bf
Copy link

bf commented Jan 26, 2017

@revett I merged this and another patch in my fork https://github.com/bf/reactable

@kidmillions
Copy link

^^^ signal boosting this, would love to see it fixed up and merged.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants