table组件插入html内容
ElementUI version
1.0.0-rc.4
OS/Browers version
macOS/Chrome 53.0.2785.116 (64-bit)
Vue version
2.0.0-beta.5
问题描述
假设场景
用户查询出一批数据,使用table显示了出来,每一条数据终归是需要一些图标或者按钮供用户点击编辑、删除或者预览
现存问题
我没有看到如何在table组件给每一列插入按钮或图标的html方法,请求协助。。
https://github.com/ElemeFE/element/blob/master/examples/docs/zh-cn/table.md#多选
参考这里关于 inline-template 的描述。里面可以自定义内容,并且可以通过 row 访问到当前行。
@Leopoldthecoder ,谢谢你的提示,已经找到解决办法,代码供其他网友参考,如下
<el-table
:data="tableData"
@cellclick="cellClick"
border
style="width: 100%">
<el-table-column
property="date"
label="日期"
width="180">
</el-table-column>
<el-table-column
property="name"
label="姓名"
width="180">
</el-table-column>
<el-table-column
property="address"
label="地址"
:formatter="formatter">
</el-table-column>
<el-table-column
inline-template
label="操作">
<el-button-group>
<el-button type="primary" icon="edit" size="small"></el-button>
<el-button type="primary" icon="share" size="small"></el-button>
<el-button type="primary" icon="delete" size="small"></el-button>
</el-button-group>
</el-table-column>
</el-table>
@KeroVieux 能够分享一下js代码么, 获取每行数据的时候遇到问题了, 谢谢
@zhwei820 查看element官方文档,查找关键字「cellclick」,一看就知道怎么用啦!基本上能用到的数据都能获取到
@Leopoldthecoder el-table-column标签我是用v-for动态生成的, <el-table-column v-for="currentThead of currentTheadData" :prop='currentThead.prop' :label='currentThead.label' :formatter="currentThead.formatter" width="180">
</el-table-column>
我想到了formatter,但是无法插入html,html会原样输出,请教如何解决呢
使用Scoped slot进行formatter,这就限制了el-table-column不能动态生成了,formatter这个属性也没啥使用场景了
我现在也遇到这个问题了,请问楼上这个问题解决了没 @xchz 。用formatter,html会直接输出到浏览器
同样的问题: table组件如何输出html 官方做法有两种 1.不可配置方式: template slot进去,这样的坏处就是无法动态渲染 2 在data中配置方式: template slot进去, 通过
动态渲染,这种方式需要tableData中先定义好html,可一般tableData都是接口返回,不会含有操作内容
@Jim-MK 参考vuetify,以前用bootstrap-table也是这样的api设计。开发人员忙着知乎上和iview撕逼没空回答问题😄
@xchz 可以给个案例吗😄
@xchz 你好这个问题最终怎么解决的,谢谢
解决方法:在column 的formatter方法中使用形如 this.$createElement("div","test") 课插入html version:"1.3.7" eg:https://jsfiddle.net/wipphj/Lqxjwe68/
<template slot-scope="scope">
<span v-if="col['inline-template']" v-html="scope.row[col.prop]"></span>
<template v-else-if="col['type']==='index'">{{scope.$index+1}}</template>
<template v-else>{{scope.row[col.prop]}}</template>
</template>
col是循环列的配置
elemenui的table怎么由后端返回表头和表的列然后渲染???