GriddleGriddle / Griddle

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

Manipulate data in ColumnDefinition #772

Closed zzz-code closed 7 years ago

zzz-code commented 7 years ago

Hi, i like to know if it is possible to manipulate the data that is being set to the ColumnDefinition component. I fetch some json data from a API. For example I like to add some currency format settings or a $ before my price data with Numbro.

const format = this.price_usd > 1 ? '0,0.00' : '0,0.[000000]';
const price = numbro(this.price_usd).format(format);
--
<ColumnDefinition id="price" title="Price" />

But this is not working. Is there a way to do this with Griddle?

dahlbyk commented 7 years ago

Try customComponent:

const Price = ({ value }) => (
  <span>{numbro(value).format(value > 1 ? '0,0.00' : '0,0.[000000]')}</span>
);
--
<ColumnDefinition id="price" title="Price" customComponent={Price} />
zzz-code commented 7 years ago

Thnx that works