将Ag-grid与数组绑定

时间:2019-02-08 07:09:31

标签: ag-grid

我有一个值为array = [3,4]的数组。如果它与数组值匹配,我必须显示ag-grid值。这是我到目前为止尝试过的:

随行随行者:https://plnkr.co/edit/fKrvfzFYjdLbTLjFkqpY?p=preview

 var array=[3,4];
 var columnDefs = [
      {headerName: "Jobs",field: "job", width: 90},
      {headerName: "Location", field: "loc", width: 120 },
      {headerName: "Value", field: "value", width: 120 }];

 var rowData =[{job:'Developer',loc:'X',value:1},
            {job: 'Manager',loc:'Y',value:2},
            {job: 'Musician',loc:'Z',value:3},
            {job: 'Manager',loc:'A',value:4},
            {job: 'Tester',loc:'B',value:5},
            {job: 'DBA',loc:'C',value:6}
       ];

var gridOptions = {
defaultColDef: {
    sortable: true
},
columnDefs: columnDefs,
animateRows: true,
enableRangeSelection: true,
rowData: rowData,
checkbox : true
};

当值字段值与数组值匹配时如何显示网格。

1 个答案:

答案 0 :(得分:0)

这是一个有工作实例的小伙子-https://plnkr.co/edit/xdwI0Tql9I5n71D4QSDy?p=preview

像在值列的列定义中那样添加自定义cellRenderer函数

{
  headerName: "Value",
  field: "value",
  width: 120,
  cellRenderer: params => array.includes(params.value) ? params.value : ''
}