1

How to load the following array object mark "name" values in cell.

Here the object looks like

 {
      id: "1"
      mark: [
        0: {name: "AUS", id: 1000}
        1: {name: "BRA", id: 1050}
        2: {name: "CHN", id: 1100}
        3: {name: "ECE", id: 1200}
        4: {name: "EG", id: 1250}
        5: {name: "JAP", id: 1450}
        6: {name: "RUS", id: 1500}
      ]
    }

HTML

<ag-grid-angular #agGrid style="width: 100%; height: 100%;" id="myGrid" class="ag-theme-balham cis-ag-grid"
      [columnDefs]="columnDefs" [defaultColDef]="defaultColDef" [rowSelection]="rowSelection" [rowData]="rowData"
      [context]="context" [frameworkComponents]="frameworkComponents" (selectionChanged)="onSelectionChanged()"
      (rowClicked)='onRowClicked($event)' (gridReady)="onGridReady($event)" [gridOptions]="gridOptions">
    </ag-grid-angular>

TS Inside constructor (),

this.defaultColDef = {
      resizable: true,
      sortable: true,
      filter: true,
      headerComponentParams: { menuIcon: 'fa fa-filter' }
    };

this.columnDefs = [  
{
  headerName: "ID",            
  minWidth: 144,
  field: "id", 
  valueGetter: "data.id"
},
{
  headerName: "Mark",            
  minWidth: 144,
  field: "mark", 
  valueGetter: "data.mark.name"
}];

currently, It is displaying in grid column cell like,

ID        Mark
--------------
1         [object Object], [object Object], [object Object], [object Object], 
          [object Object], [object Object], [object Object]

Expected is,

ID        Mark
  --------------
   1       AUS, BRA, CHN, ECE, EG,JAP,RUS
4
  • 1
    Show the HTML file and component code Commented Jul 18, 2019 at 4:45
  • Updated the post with expected result Commented Jul 18, 2019 at 4:47
  • 1
    Hi, I am asking about .html and .ts file. Commented Jul 18, 2019 at 4:49
  • Updated the post HTML and ts Commented Jul 18, 2019 at 5:22

6 Answers 6

2

Try to this for Ag-grid.

Set Column:-

constructor() {
 this.columnDefs = [                    
  {
    headerName: 'Id', sortable: true, resizable: true, valueGetter: 'data.mark.id'
  },
  {
    headerName: 'Mark', sortable: true, resizable: true, valueGetter: 'data.mark.name'
  }
 ]
}

In typescript file :-

public dataMarkList:any;

constructor() {

}

yourGetFunction() {
   this.dataMarkList = data.mark
}

And set rowData properties in ag-grid like

<ag-grid-angular class="ag-theme-material" style="width: 100%; height: calc(100vh - 200px);" rowSelection="single"
   animateRows="true" [rowHeight]="43" [columnDefs]="columnDefs" rowModelType="infinite"
   paginationPageSize="50" [rowData]="dataMarkList">
</ag-grid-angular>
Sign up to request clarification or add additional context in comments.

1 Comment

Can you please provide right code for this [rowData]="dataMarkList". This is not working. Also column filter data is not updating based on the grid data.
1

Since there isn't any HTML code provided, you can try:

<span *ngFor="let obj of data.mark">
 {{ obj.name }},
</span>

inside that HTML column.

It's coming as [object Object] because it an object ({name: "AUS", id: 1000}). You can visualize it by putting pipe as | json in {{ obj | json }}

1 Comment

I'm using ag grid directive. Not the html
0

there is no html provided so a reproducible plunker or stackblitz will help. Try like this:

<div *ngFor="let data of dataList">
     <span *ngFor="let item of data.mark">
        {{ item .name }},
      </span>
 </div>

1 Comment

Update the post. I'm using ag-grid directive.
0

I used Cell Renderer to accomplish this. I use Vue not Angular. This is how I did it in Vue.

I created a Cell Renderer component file called CellRenderList.vue and imported it into the parent. For defining the field in the parent file I did.

headerName: 'SomeName',
field: 'mark',
cellRendererFramework: 'CellRendererList',

Importing the component and adding that cell renderer line should be the only thing you need to do on your original file.

My CellRenderList.vue component file looks like this.

<template>
 <div class="">
  <span v-for="(value, index) in mark">
    <span v-if="index != 0">, </span><span>{{ value.name }}</span>
  </span>
 </div>
</template>

<script>
  export default {
    name: 'CellRendererList',
    computed: {
      mark() {
        return this.params.data.mark
      }
    }
  }
</script>

The Ag Grid documentation on Cell Renderer has some good examples how to do it in Angular.

Comments

0
this.columnDefs = [  
{
  headerName: "ID",            
  minWidth: 144,
  field: "id",
},
{
  headerName: "Mark",            
  minWidth: 144,
  field: "mark", 
  valueGetter: (row: any) => {
        return row.data.mark.name;
      },
}];

Comments

0

this works for me:

{
  headerName: 'SomeName',
  field: 'mark',
  valueGetter: (row: any) => {
    return row.data.mark.map((mark: any) => profile.name);
  },
},

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.