Working with Flexgrid as Vue.JS Component

Posted by: rbutler on 7 November 2018, 7:14 pm EST

    • Post Options:
    • Link

    Posted 7 November 2018, 7:14 pm EST - Updated 3 October 2022, 8:18 pm EST

    Working with Flexgrid as Vue.JS Component

    Hi,

    I am evaluating Flexgrid (grid.5.20182.524) for my employer for inclusion in a new product.

    I am attempting to set up flexgrid as a Vue2 (vue.2.5.17) component and I need to configure this grid dynamically as both row and column setup will change based on user actions.

    Here is my code:

    Vue.component("worklist-grid-panel",
        {
            data() {
                return {
                    worklistRows: [
                        {
                            "entryId": "VSW-12a3e4-4220-23 00", "entryType": "Receipt",
                            "entryDate": "10/11/12", "entryStatus": "Received in", "entrySubclass" : "1906 Blazer", "entryStyle" : "Alpha"
                        }
                    ],
                    columns: [],
                }
            },
            created() {
                this.columns.push({ binding: 'entryId', header: 'Worklist ID', type: 'String' });
                this.columns.push({ header: ' ', type: 'String' });
                this.columns.push({ binding: 'entryType', header: 'Type', type: 'String' });
                this.columns.push({ binding: 'entryDate', header: 'Date', type: 'Date' });
                this.columns.push({ binding: 'entryStatus', header: 'Status', type: 'String' });
                this.columns.push({ binding: 'entrySubclass', header: 'Subclass', type: 'String' });
                this.columns.push({ binding: 'entryStyle', header: 'Style', type: 'String' });
                console.log("grid is created");
            },
            mounted() {
                console.log("grid is mounted");
                console.log(this.$el);
            },
            template:
                `<wj-flex-grid auto-size-mode="Both" 
                    :items-source="worklistRows" :auto-generate-columns="false"  ref="myWL">
                    <wj-flex-grid-cell-template cell-type="TopLeft">X</wj-flex-grid-cell-template>
                    <wj-flex-grid-column :col="col"  v-for="col in columns" width="*" :allow-sorting="true"
                        :binding="col.binding" :header="col.header" :type="col.type">
                    </wj-flex-grid-column>
                </wj-flex-grid>`
        });
    

    The render of this grid is in the attached image.

    First, is this a valid way to instantiate the grid?

    Second,

    The tasks I am attempting accomplish are:

    1. Change the row header cells to render checkboxes to select rows
    2. Change the topleft cell to be a checkbox to select ALL rows.
    3. Add a row to the left of the row header (or alternately, hide the default header row and make my own row header)

    I want to do these things in a function in the Vue component. This component will be reused by other teams.

    The problems I am having:

    1. I have not been able to modify the row header (the screenshot shows how wj-flex-grid-cell-template renders outside the grid).
    2. While I found a way to access the grid control using the vue ref attribute (this.$refs.myWL in the code above), I do not see a way to modify the header markup to use checkboxes.

    While I found some jsfiddles that had wijmo, they were not up-to-date with wijmo’s latest vue library.

    Can anyone help with this?

  • Posted 8 November 2018, 6:51 am EST

    Hi,

    Thanks for evaluating Wijmo.

    Yes, this is a valid way to instantiate the grid, however, there is two issue in the snippet provided:

    1). wj-flex-grid-cell-templates are available only for angular/angular2 interop so they can’t be used in Vue.

    2). The data type of a column is defined using the dataType property instead of type. Please refer to the following code snippet:

    <wj-flex-grid-column
            :col="col"
            v-for="col in columns"
            width="*"
            :allow-sorting="true"
            :binding="col.binding"
            :header="col.header"
            :data-type="col.type"
          >
     </wj-flex-grid-column>
    

    The tasks I am attempting accomplish are:

    1. Change the row header cells to render checkboxes to select rows
    2. Change the topleft cell to be a checkbox to select ALL rows.
    3. Add a row to the left of the row header (or alternately, hide the default header row and make my own row header)

      <<<<<<<<<<<<

      For 1 and 2, you may use formatItem event to easily format the grid cells as required.

      3). You may add any no of extra row header by pushing Column instances on grid.rowHeader collection.

      Please refer to the following sample which demonstrates the same:

      https://codesandbox.io/s/ooq8y95045

    Regards

    Sharad

  • Posted 8 November 2018, 10:23 am EST

    Thank you very much, Sharad, this looks great and answers my questions!

  • Posted 8 November 2018, 2:15 pm EST

    Sharad, are we able to set the name property of a column? I tried the following but no luck:

    this.columns.push({ name: ‘Test’, binding: ‘entryId’, header: ‘Worklist ID’, type: ‘String’ });

  • Posted 9 November 2018, 1:02 am EST

    Yes, we can customize the name of a Column.

    After adding the name property to the columns definition array(this.columns), we need to map it the name property of the column.

    Please refer to the following code snippet:

    <wj-flex-grid-column
            :col="col"
            v-for="col in columns"
            width="*"
            :allow-sorting="true"
            :binding="col.binding"
            :header="col.header"
            :data-type="col.type"
            :name="col.name"
          >
    

    ~Sharad

  • Posted 9 November 2018, 10:34 am EST - Updated 3 October 2022, 8:18 pm EST

    Ugh.

    Thanks, Sharad.

    Please enjoy the attached image.

Need extra support?

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

Learn More

Forum Channels