admin管理员组文章数量:1394099
I need an editable datagrid on an application written with Element UI.
Actually, I've a table like the following:
<el-table :data="myData" stripe="stripe">
<el-table-column prop="col1" label="Col 1"></el-table-column>
<el-table-column prop="col2" label="Col 2"></el-table-column>
</el-table>
That's rendered in html like (simplifying):
<table class="el-table__body">
<td class="el-table_1_column_1">
<div class="cell">Val col 1</div>
</td>
<td class="el-table_1_column_1">
<div class="cell">Val col 1</div>
</td>
</table>
So, I'd like to append the attribute contenteditable="true"
to the div with class="cell"
.
I tried to append the attribute to the el-table-column
element, but it didn't works.
<el-table-column prop="position" label="Pos." contenteditable="true"></el-table-column>
Then, how could I make some el-table's cell editable?
Is the contenteditable
attribute the right way? How can I use it?
Thanks.
I need an editable datagrid on an application written with Element UI.
Actually, I've a table like the following:
<el-table :data="myData" stripe="stripe">
<el-table-column prop="col1" label="Col 1"></el-table-column>
<el-table-column prop="col2" label="Col 2"></el-table-column>
</el-table>
That's rendered in html like (simplifying):
<table class="el-table__body">
<td class="el-table_1_column_1">
<div class="cell">Val col 1</div>
</td>
<td class="el-table_1_column_1">
<div class="cell">Val col 1</div>
</td>
</table>
So, I'd like to append the attribute contenteditable="true"
to the div with class="cell"
.
I tried to append the attribute to the el-table-column
element, but it didn't works.
<el-table-column prop="position" label="Pos." contenteditable="true"></el-table-column>
Then, how could I make some el-table's cell editable?
Is the contenteditable
attribute the right way? How can I use it?
Thanks.
Share Improve this question edited Dec 13, 2017 at 13:32 Alessandro asked Dec 13, 2017 at 12:05 AlessandroAlessandro 4,4729 gold badges42 silver badges71 bronze badges1 Answer
Reset to default 3Well, I solved adding a template
inside any column, each one can access to the parent scope
specifying the attribute slot-scope="scope"
. In this way, the inner input can be bounded with the column of each row.
Then, I've implemented my table like following:
<el-table :data="myData" stripe="stripe">
<el-table-column prop="col1" label="Col 1">
<template slot-scope="scope">
<el-input-number v-model="scope.row.col1" :min="1" :max="99" size="small" controls-position="right" />
</template>
</el-table-column>
<el-table-column prop="col2" label="Col 2"></el-table-column>
</el-table>
In the above code, the col1
is bounded with the datasource's table myData
on col1
, through the attribute v-model="scope.row.col1"
.
Obviously, in the template you can insert anything you need: el-input
, el-input-number
or even custom ponents.
Note: You can choose to make editable just some columns, as you can see in the above example (the second column is not editable).
本文标签: javascriptVuejsElement UI Content editable on eltable39s rowsStack Overflow
版权声明:本文标题:javascript - Vue.js + Element UI: Content editable on el-table's rows - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744722184a2621759.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论