简体   繁体   English

如何在单个 ag-grid 单元格中显示两列值?

[英]How to display two column values in a single ag-grid cell?

I have a record of First_Name and Second_Name stored in MySql DB.我在 MySql DB 中存储了 First_Name 和 Second_Name 的记录。 Currently I am displaying it in 2 different columns of Ag-Grid.目前我在 Ag-Grid 的 2 个不同列中显示它。 I need those data to be combined together as Name and to be displayed in Ag-Grid's single column.我需要将这些数据组合在一起作为名称并显示在 Ag-Grid 的单列中。 Please help!请帮忙!

I am using Vue.Js我正在使用 Vue.Js

You should use a valueGetter in your columnDef like this -您应该像这样在您的 columnDef 中使用valueGetter -

  {
    headerName: 'Name',
    colId: 'name',
    valueGetter: function(params) {
      return params.data.First_Name + " " + params.data.Second_Name;
    },
  },

Example from docs here 此处的文档示例

The ans stated by Pratik is right. Pratik 所说的答案是正确的。 Maybe you can use arrow functions for valueGetter so that the code looks more concise and simplify function scoping.也许您可以对 valueGetter 使用箭头函数,以便代码看起来更简洁并简化 function 范围。
{ headerName: 'Name', valueGetter: params => { return ${params.data.First_Name} ${params.data.Second_Name} ; { headerName: 'Name', valueGetter: params => { return ${params.data.First_Name} ${params.data.Second_Name} ; }, }, }, },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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