简体   繁体   中英

How to use cellRenderer in ag-grid table react js

i created table using react js ag-grid method after that i just pass my json data into react table.

My json file data:

{
  "posts": [{
    "cam1": " 3 persons, 1 car, 1 bottle, 2 chairs, 1 tv",
    "cam2": " 1 person",
    "date": "Tue, 19 April 12:16:29 ",
    "status": "High"
  }, {
    "cam1": " 3 persons, 2 chairs, 1 tv",
    "cam2": " 1 person",
    "date": "Tue, 19 April 12:16:32 ",
    "status": "Low"
  }, {
    "cam1": " 4 persons, 1 bottle, 2 chairs, 1 tv",
    "cam2": " 1 person",
    "date": "Tue, 19 April 12:16:35 ",
    "status": "Medium"
  }]
}

I just passed this json data into react table. after passing the data to table像这样反应表

Now i expected to highlight status with color coding with some conditions.

if status is high highlight with red, if status is medium highlight with yellow, else highlight with green.

Expected output model like this: 在此处输入图像描述

How can i do this with react js ag-grid table method. for more code reference Click Here

you are looking for cellRenderer .

You can create one component StatusCellComponent and apply all styles that needed

here you can find some examples: https://www.ag-grid.com/react-data-grid/component-cell-renderer/#complex-cell-renderer-example

here you can find more info: https://www.ag-grid.com/react-data-grid/component-cell-renderer/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM