Coder Social home page Coder Social logo

Comments (6)

jimmybutton avatar jimmybutton commented on June 17, 2024 2

Hi @arnigunnar, just for you to know, I've switched to using React Table (https://react-table.tanstack.com/). It's a bit more work to set it up but it works great and allowes for more customization.

from gridjs-react.

jimmybutton avatar jimmybutton commented on June 17, 2024

I've tried a few things but still wasn't able to make this work. Here is another approach I tried:

import { useHistory } from "react-router-dom";

const CellLink = ({ item }) => {
  let history = useHistory();
  function handleClick() {
    history.push(`/jobs/${item.jobId}`);
  }
  return (
    <button onClick={handleClick} className="font-bold">
      View
    </button>
  );
};

...

<Grid
  data={data.map((item) => ({
    ...item,
    button: _(<CellLink item={item} />),
  }))}
  columns={columns}
/>

If i use CellLink outside Grid it works, but if I use it in a cell, I get TypeError: Cannot read property 'push' of undefined.

Any advice would be greatly appreciated.

from gridjs-react.

stale avatar stale commented on June 17, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from gridjs-react.

arnigunnar avatar arnigunnar commented on June 17, 2024

Is there any way of reopening this, as I am having exactly the same issue.

formatter: (cell) => _(<Link to="/this-should-be-the-link">{ cell }</Link>)

from gridjs-react.

a-r-i-e-l avatar a-r-i-e-l commented on June 17, 2024

Send the history as a prop to CellLink

import { useHistory } from "react-router-dom";

const CellLink = ({ item, history }) => {
  function handleClick() {
    history.push(`/jobs/${item.jobId}`);
  }
  return (
    <button onClick={handleClick} className="font-bold">
      View
    </button>
  );
};

...

const WrapperComponent = () => {
  const history = useHistory();
  return (
    <Grid
      data={data.map((item) => ({
        ...item,
        button: _(<CellLink item={item} history={history} />),
      }))}
      columns={columns}
    />
  )
}

from gridjs-react.

dhoonbae avatar dhoonbae commented on June 17, 2024

I solved !

https://gridjs.io/docs/examples/cell-attributes

const grid = new Grid({
columns: [
{
name: 'Name',
attributes: (cell) => {
// add these attributes to the td elements only
if (cell) {
return {
'data-cell-content': cell,
'onclick': () => alert(cell),
'style': 'cursor: pointer',
};
}
}
},
'Email',
],
data: Array(5).fill().map(x => [
faker.name.findName(),
faker.internet.email(),
])
});

[ react ]
import { useHistory } from 'react-router-dom';
const history = useHistory();
...
onclick : () => history.push('/link')

from gridjs-react.

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.