Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table will not be updated with dynamical columns #17

Open
sknightq opened this issue Aug 1, 2018 · 2 comments
Open

Table will not be updated with dynamical columns #17

sknightq opened this issue Aug 1, 2018 · 2 comments

Comments

@sknightq
Copy link

sknightq commented Aug 1, 2018

My columns are the date, which is depended on the user's time select. Such as 2018-08-01, 2018-08-02,2018-08-03 and so on. So my column slot like following:

<v2-table>
  <v2-table-column v-for="(column,index) in columns" :key="index" :label="column.label" :width="column.width" :prop="column.key"></v2-table-column>
</v2-table>

when columns are updated, table will not be updated

@dwqs
Copy link
Owner

dwqs commented Aug 3, 2018

do you have a reproduce demo

@sknightq
Copy link
Author

sknightq commented Aug 8, 2018

@dwqs I had got my aim with my custom code. Because the component instance of columns'slots can't be got in updateColumnsWidth function, which results in the wrong width of the table when columns' slot updated. Your code only call the updateColumnsWidth in mounted hook.
So I recall the handleWinResize in updated hook with this.$nextTick method. Of course, I add some computed attributes in child component "table-body.js"

some code snippets:

// table.vue
// to update the columns width
        updated () {
            this.$nextTick(function () {
                this.handleWinResize();
                if (this.rowsChange) {
                    this.updateScrollbar(true);
                    this.rowsChange = false;
                }        
            });
        }
// table.vue
// detect neccessary resize
            handleWinResize () {
                const newColumns = this.$slots.default.filter(function (column) {
                    return column.componentInstance && column.componentInstance.$options.name === 'v2-table-column';
                }).map(function (column) {
                    return column.componentInstance;
                });

                if (this.$el.clientWidth === this.containerWidth && this.columns.length === newColumns.length) {
                    return;
                } else {
                    this.bodyMinWidth = undefined;
                }

                this.containerWidth = this.$el.clientWidth;
                this.containerHeight = this.$el.clientHeight;
                
                // this.columns = [].concat(this.updateColumnsWidth(this.columns));
                this.columns = [].concat(this.updateColumnsWidth());

                if (this.rightColumns.length) {
                    this.rightColumns = [].concat(this.getColumnComponentsByType(this.columns, 'right'));
                }
                if (this.leftColumns.length) {
                    this.leftColumns = [].concat(this.getColumnComponentsByType(this.columns, 'left'));
                }

                if (this.scrollbar) {
                    this.updateScrollbar(true);
                }
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants