javascript - Custom column header in el-table not reactive - Stack Overflow

I am using vuejs 2.6.10 and element-ui 2.12.0 and displaying data inside an el-table. So far so good.In

I am using vuejs 2.6.10 and element-ui 2.12.0 and displaying data inside an el-table. So far so good.

In the column headers, I would like to display input fields to filter the data but I want to display these inputs only on demand (upon clicking a button). So I wanted to use custom headers like this:

<el-table-column prop="name" label="Name" width="180">
    <template slot="header">
        Name <br/>
        <!-- show input only on demand -->
        <el-input v-show="bool"></el-input>
    </template>
</el-table-column>

And here es the problem: nothing happens when the value of bool changes.

After a few testing I realized that the header template doesn't seem to be reactive.

I've found a workaround to toggle my inputs: forcing the el-table to re-render...

<el-table v-if="showTable" ...>
methods: {
    toggleInputs() {
        // toggle bool
        this.bool = !this.bool;

        // force re-render table...
        this.showTable = false;
        this.$nextTick(() => (this.showTable = true));
    }
}

It works. But this is not clean at all and it takes some time to re-render a not-so large table...

Here is the full example: /

Has someone a better solution to make custom headers reactive?

I am using vuejs 2.6.10 and element-ui 2.12.0 and displaying data inside an el-table. So far so good.

In the column headers, I would like to display input fields to filter the data but I want to display these inputs only on demand (upon clicking a button). So I wanted to use custom headers like this:

<el-table-column prop="name" label="Name" width="180">
    <template slot="header">
        Name <br/>
        <!-- show input only on demand -->
        <el-input v-show="bool"></el-input>
    </template>
</el-table-column>

And here es the problem: nothing happens when the value of bool changes.

After a few testing I realized that the header template doesn't seem to be reactive.

I've found a workaround to toggle my inputs: forcing the el-table to re-render...

<el-table v-if="showTable" ...>
methods: {
    toggleInputs() {
        // toggle bool
        this.bool = !this.bool;

        // force re-render table...
        this.showTable = false;
        this.$nextTick(() => (this.showTable = true));
    }
}

It works. But this is not clean at all and it takes some time to re-render a not-so large table...

Here is the full example: https://jsfiddle/olivierlevrey/pyvc6kht/2/

Has someone a better solution to make custom headers reactive?

Share Improve this question edited Sep 11, 2019 at 13:16 41 72 6c 1,7806 gold badges22 silver badges36 bronze badges asked Sep 11, 2019 at 12:57 Olivier LevreyOlivier Levrey 1151 silver badge10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Looks like your template is not recognizing the scope. Adding slot-scope solves your problem.

https://jsfiddle/cz8tm9bd/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744843693a4596708.html

相关推荐

  • javascript - Custom column header in el-table not reactive - Stack Overflow

    I am using vuejs 2.6.10 and element-ui 2.12.0 and displaying data inside an el-table. So far so good.In

    2天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信