Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to pass row data into formatter #42

Closed
maiis opened this issue Jul 31, 2015 · 14 comments
Closed

Document how to pass row data into formatter #42

maiis opened this issue Jul 31, 2015 · 14 comments

Comments

@maiis
Copy link

maiis commented Jul 31, 2015

I had a case where I needed to access others row values inside a cell formatter. Maybe be worth documenting it ?

This is how I achieved it.

let columns = [
    ...
    {
        key: 'mykey',
        name: 'My Column',
        formatter: Formatters.myFormatter,
        getRowMetaData: (row) => row
    }
    ...
];

In into my formatter I can access all the row values into this.props.dependentValues

@bakesteve
Copy link

we'll track this under #41 as they will have a common solution.
Generally, we feel that a cell (formatter or editor) should not have access to the row data, but there are cases where you need access to some other props. We'd like to be explicit - but still allow people to provide the access if they need it. The solution above works fine, but we'd like to have a cleaner implementation though. Will update the docs too

@maiis
Copy link
Author

maiis commented Jul 31, 2015

👍

@lmaccherone
Copy link

I used this getRowMetaData trick myself. Thanks for posting here. Let me know if you add some other mechanism, but I like the current one.

@maxcc0
Copy link

maxcc0 commented Sep 27, 2016

thanks @maiis, Just what i was looking for.

@anil1712
Copy link

Yeah its great solution but I needed header info also. Is there any solution for the same?

@urbinopescada
Copy link

I've been 2 hours searching for this!!!

@jamesajones
Copy link

If I use the above column definition what does the static propTypes {} look like?

@Gtosta96
Copy link

It should be well documented 👍

@jamesajones
Copy link

Where

@vellov
Copy link

vellov commented Jul 26, 2018

Holy crap, I looked for this crap for almost 2 hours. This documentation is the worst i've seen.

@Gtosta96
Copy link

Yes, such a pity, since the library is very cool...

@Nodios
Copy link

Nodios commented Sep 18, 2018

Damn! @maiis you just saved me tons of time!

@usersina
Copy link

usersina commented Mar 7, 2021

Having the same issue, couldn't replicate the provided solution using JSX as a formatter because it throws a promise rejected exception.

Instead I'm using a function but I can't view the row data.

let columns = [
    ...
    {
      id: 'status',
      name: 'Status',
      getRowMetaData: (row) => row,
      formatter: (_s, _o, rowObject) => _(renderStatus(rowObject)),
    },
    ...
];
const renderStatus = (rowObject) => {
    console.log(rowObject.getRowMetaData); // Returns the string "row => row"
    return <StatusTest myVar={rowObject} />;
};
"gridjs": "^3.3.0",
"gridjs-react": "^3.2.2",

@ps1011
Copy link

ps1011 commented Aug 9, 2023

In case anyone still searching for this, we can access row data with params.row for custom rendering which depends on other row data

const columns=[
{
    headerName: "Duration",
    key: "duration",
    description: "run duration",
    // getRowMetaData: (row) => row,
    sortable: true,
    type: "string",
    valueGetter: (params) => {
      console.log("row dat",params.row); // row data object
      const endDate = params.row.completed_date
        ? moment.utc(params.row.completed_date)
        : moment.utc(new Date());
      const startDate = moment.utc(params.row.created_date);
      var diff = moment.duration(endDate.diff(startDate));
      const duration = [diff.hours(), diff.minutes(), diff.seconds()].join(":");
      return duration + " Hrs";
    },
   valueFormatter: (params)=>{
       console.log("row dat",params.row); // row data object
   }
  },
]

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

No branches or pull requests