GriddleGriddle / Griddle

Simple Grid Component written in React
http://griddlegriddle.github.io/Griddle/
MIT License
2.5k stars 378 forks source link

Use inner HTML on <td> #794

Open MahbbRah opened 6 years ago

MahbbRah commented 6 years ago

This is the object passing to ` { id: k, Name: v.timer_name, Impressions: v.impressions, Clicks: v.clicks, Status: v.timer_status, End_Date: v.clicks, Actions:

  • Copy Code
  • Edit
  • Duplicate
  • Remove
            </div></td>`
        }

``

Current Output: image

The Problem is HTML inside the Actions column isn't rendering and I do not want to show: griddleKey column with its data. Please, Help me with this configuration. I cannot see anything in the docs like that.

mpolinowski commented 6 years ago

+1 same issue - could not find a solution yet.

dahlbyk commented 6 years ago

To hidde griddleKey, you need to explicitly list the expected <ColumnDefinition />s. For Actions, try a customComponent that uses dangerouslySetInnerHTML:

const htmlComponent =
  ({ value }) =>
    <div dangerouslySetInnerHTML={{ __html: value }} />;

class MyGrid extends React.Component {
  render() {
    return (
      <Griddle data={...}>
          <RowDefinition>
            <ColumnDefinition id="id" />
            <ColumnDefinition id="Name" />
            <ColumnDefinition id="Impressions" />
            <ColumnDefinition id="Clicks" />
            <ColumnDefinition id="Status" />
            <ColumnDefinition id="End_Date" />
            <ColumnDefinition id="Actions" customComponent={htmlComponent} />
          </RowDefinition>
      </Griddle>
    );
  }
}
MahbbRah commented 6 years ago

@dahlbyk Hey Thanks for your help, Can I use Object , Array instead of customComponent ?

dahlbyk commented 6 years ago

I don't understand the question. customComponent is the prop you use to specify how a column value should be rendered. If your column value is an Object or an Array, you can teach your customComponent to render from that.