question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to get the data by 'griddleKey'?

See original GitHub issue

Griddle version

^1.10.0

Problem

So I’m using my own RowEnhancer, so I can implement my own onClick, like this:

const components: GriddleComponents = {
  RowEnhancer: (OriginalRow: GriddleComponent<GriddleRowProps>) => (props: GriddleRowProps) => (
    <OriginalRow
      {...props}
      onClick={() => {
        console.log(`Clicked Row ${props.griddleKey}`);
        console.log('props', props);
      }}
    />
  ),
};

When I click on the row, I get the following log:

Click Row 32
props {griddleKey: 32, columnIds: Array(3), className: "griddle-row", Cell: ƒ}

The griddleKey here would be useful to get al the row-data back I guess, but I can’t seem to find out how this should be done. 😕

Can somebody help me please?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
dahlbykcommented, Dec 6, 2017

@MichaelDeBoey take a look at https://codesandbox.io/s/r50q23027o.

You’re using rowDataSelector in a context that has access to your app store rather than Griddle’s internal store; you need to use the selector inside a <Griddle /> and with utils.connect (or simply { connect } from 'griddle-react', as of #751).

I did mess up my example slightly; EnhanceWithRowData needs to be composed. It also occurs to me that withHandlers is a better way to create onClick:

const EnhanceWithRowData = utils.connect((state, props) => ({
  rowData: selectors.rowDataSelector(state, props)
}));

const components = {
  RowEnhancer: compose(
    EnhanceWithRowData,
    withHandlers({
      onClick: props => () => {
        console.log(`Clicked Row ${props.griddleKey}`);
        console.log('props', props);
      },
    })
  ),
};
2reactions
dahlbykcommented, Nov 9, 2017

You’ll get better performance using the rowDataSelector that’s exported from Griddle (via our Storybook). You can also simplify your enhancer using recompose/mapProps:

import { selectors, GriddleComponents } from 'griddle-react';
import { connect } from 'react-redux';
import mapProps from 'recompose/mapProps';

const EnhanceWithRowData = connect((state, props) => ({
  rowData: selectors.rowDataSelector(state, props)
}));
const components: GriddleComponents = {
  RowEnhancer: EnhanceWithRowData(
    mapProps(props => ({
      ...props,
      onClick: () => {
        console.log(`Clicked Row ${props.griddleKey}`);
        console.log('props', props);
      },
    }))
  ),
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

ReactJS - Griddle v1.0 get current filtered data - Stack Overflow
Im trying to figure out how to get the current filtered items from the Griddle component. I found the following function in the...
Read more >
Get data from Row into Cell | Griddle
Griddle supports getting data from Row into Cell. First we need two helpers: row data selector and connect-wrapper: import { connect } from...
Read more >
[Solved]-Selecting a Row in React Griddle, and changing tr ...
setState({ selectedRowId: row.props.data.id }); } render() { const ... I'm assuming that something must have changed in Griddle over the past two years....
Read more >
How to create a customized data grid using griddle-react
You can just change the component rendered from App to change the components according to the tutorial. All code snippets will also be...
Read more >
DynamicTyped - Bountysource
I got griddle going with external data using the sample wrapper that you provided ... Is there a way to have a custom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found