0

I am working on ag-grid component. In this grid I have to bind only column in vertical format. suppose I have an array ["0.1", "0.4", "cn", "abc"] and I have to display it in ag-grid component as below and i don't have any rowData.

    0.1
---------------------------------
    0.4
---------------------------------
    cn
---------------------------------
    abc
--------------------------------

Is it possible to bind above array in vertical format using ag-grid. or is there any other solution, Please any help will be appreciated. Thanks in advance.

my html file:

<ag-grid-angular 
    style="width: 500px; height: 500px;" 
    class="ag-theme-balham"
    [rowData]="rowData" 
    [columnDefs]="columnDefs"
    >
</ag-grid-angular>
2
  • can u change the format of the array to ["0.1"],[ "0.4"], ["cn"], ["abc"] Commented Sep 20, 2018 at 10:54
  • I am getting the same format as I have written. Commented Sep 20, 2018 at 10:58

1 Answer 1

1

you can try:

export class MyGridApplicationComponent {
    public gridOptions: GridOptions;
    public myArray =  ["0.1", "0.4", "cn", "abc"] ;

    constructor() {
        this.gridOptions = <GridOptions>{
          enableSorting: true,
          enableFilter: true
        };
        this.gridOptions.columnDefs = [
            {
                headerName: "",
                field: "value",
                width: 100
            }
        ];
        this.gridOptions.rowData = 
        this.myArray.map(function(item) {
  return {"value":item};
})
}
}

and in html:

<div style="width: 100px;">
    <ag-grid-angular #agGrid style="width: 100%; height: 200px;" class="ag-theme-fresh" [gridOptions]="gridOptions">
    </ag-grid-angular>
</div>

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

It does not show the grid after adding ag-grid-community import tag for GridOptions.

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.