element icon indicating copy to clipboard operation
element copied to clipboard

table组件插入html内容

Open KeroVieux opened this issue 10 years ago • 14 comments

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方法,请求协助。。

KeroVieux avatar Sep 28 '16 03:09 KeroVieux

https://github.com/ElemeFE/element/blob/master/examples/docs/zh-cn/table.md#多选 参考这里关于 inline-template 的描述。里面可以自定义内容,并且可以通过 row 访问到当前行。

Leopoldthecoder avatar Sep 28 '16 04:09 Leopoldthecoder

@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 avatar Sep 28 '16 05:09 KeroVieux

@KeroVieux 能够分享一下js代码么, 获取每行数据的时候遇到问题了, 谢谢

zhwei820 avatar Sep 29 '16 08:09 zhwei820

@zhwei820 查看element官方文档,查找关键字「cellclick」,一看就知道怎么用啦!基本上能用到的数据都能获取到

KeroVieux avatar Sep 29 '16 12:09 KeroVieux

@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会原样输出,请教如何解决呢

SuperChrisliu avatar Jan 09 '17 06:01 SuperChrisliu

使用Scoped slot进行formatter,这就限制了el-table-column不能动态生成了,formatter这个属性也没啥使用场景了

SuperChrisliu avatar Jan 09 '17 07:01 SuperChrisliu

我现在也遇到这个问题了,请问楼上这个问题解决了没 @xchz 。用formatter,html会直接输出到浏览器

weiyujia avatar Feb 15 '17 08:02 weiyujia

同样的问题: table组件如何输出html 官方做法有两种 1.不可配置方式: template slot进去,这样的坏处就是无法动态渲染 2 在data中配置方式: template slot进去, 通过

动态渲染,这种方式需要tableData中先定义好html,可一般tableData都是接口返回,不会含有操作内容

Jim-MK avatar Mar 16 '17 07:03 Jim-MK

@Jim-MK 参考vuetify,以前用bootstrap-table也是这样的api设计。开发人员忙着知乎上和iview撕逼没空回答问题😄

SuperChrisliu avatar Mar 16 '17 11:03 SuperChrisliu

@xchz 可以给个案例吗😄

ZYuMing avatar Jul 07 '17 09:07 ZYuMing

@xchz 你好这个问题最终怎么解决的,谢谢

wipphj avatar Aug 10 '17 10:08 wipphj

解决方法:在column 的formatter方法中使用形如 this.$createElement("div","test") 课插入html version:"1.3.7" eg:https://jsfiddle.net/wipphj/Lqxjwe68/

wipphj avatar Aug 11 '17 02:08 wipphj

      <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是循环列的配置

lefreet avatar Dec 08 '17 07:12 lefreet

elemenui的table怎么由后端返回表头和表的列然后渲染???

ShawshankLin avatar Jan 17 '18 03:01 ShawshankLin