Flexgrid -Vue 2-tyoescript can not dynamically add columns

Posted by: jingyuu.liu on 24 September 2020, 3:19 am EST

  • Posted 24 September 2020, 3:19 am EST

    Hi

    How can I dynamically create columns in the FlexGrid control?

    It only works with initial value of 'columns ’

    but failed when I tried to add columns by click the button.

    wijmo version is 5.20172.359

     
    <button @click="test">Insert New Column</button>
    <wj-flex-grid :itemsSource="ds">
          <wj-flex-grid-column
            :col="col"
            v-for="(col, index) in columns"
            :key="index"
            width="*"
            :binding="col.binding"
            :header="col.header"
          >
          </wj-flex-grid-column>
        </wj-flex-grid>
    
    
    import { Component, Vue, Watch } from 'vue-property-decorator'
    @Component({
      name: 'Demo',
      components: { }
    })
    export default class extends Vue {
    [x: string]: any
    data() {
        return {
          columns: [
            { header: 'cartype', binding: 'cartype' },
            { header: 'doccode', binding: 'doccode' }
          ]
        }
      }
     test() {
        this.columns.push({ header: 'testid', binding: 'testid' })
      }
    }
    
    

    wj-flex-grid-cell-template also dit not work here. I’m not sure if 'wj-flex-grid-cell-template ’ works .

  • Posted 25 September 2020, 9:45 am EST

    Hi Cheryl,

    You need to update the columns instance for the change detection mechanism to register it. Please refer to the following sample demonstrating the same:

    https://codesandbox.io/s/wijmo-vue-forked-hdssb?file=/src/components/HelloWorld.vue

    Regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels