# Ionic grid how to set col-x programmatically

**URL:** <https://forum.ionicframework.com/t/ionic-grid-how-to-set-col-x-programmatically/129192>\
**Category:** ionic-v3\
**Created:** [April 28, 2018, 9:56am UTC](https://forum.ionicframework.com/t/ionic-grid-how-to-set-col-x-programmatically/129192 "2018-04-28T09:56:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![landal79](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/landal79/32/117660_2.png) [@landal79](https://forum.ionicframework.com/u/landal79)\
**Post date:** [April 28, 2018, 9:56am UTC](https://forum.ionicframework.com/t/ionic-grid-how-to-set-col-x-programmatically/129192/1 "2018-04-28T09:56:56Z")

</div>

let’s say I have a matrix to display with ionic grid.  
I would apply ionic grid col width dinamically depending on the column content.

```auto
 <ion-grid>   
    <ion-row *ngFor="let row of matrix">
      <ion-col *ngFor="let val of row; let i = index"
               [ngClass]="columnsWidth[i]" >
        {{val}}
      </ion-col>
    </ion-row>
  </ion-grid>

```

Where `columnsWidth` is an array with size the number of matrix columns,  
for istance if matrix is 3X3, `columnsWidth = ['col-2','col-8','col-4']`

The result html col element attribute contains col-x but it’s not applied, how can I make it work?  
Thanks

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:38pm UTC](https://forum.ionicframework.com/t/ionic-grid-how-to-set-col-x-programmatically/129192/2 "2021-07-19T21:38:22Z")

</div>

Closed on July 19, 2021, 9:38pm UTC


