一、vue+elementUI实现 分页表格前的多选

多选效果图:

代码如下:

<el-table
ref="multipleTable"
:data="listData"
tooltip-effect="dark"
:default-sort="{ prop: 'date', order: 'descending' }"
:stripe="true"
:max-height="TABLEHEIGHT"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" min-width="55"></el-table-column>
<el-table-column label="ID" prop="id" align="left" width="80"></el-table-column> <div class="city-list-body-pagination">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-size="pageSize"
layout="total, prev, pager, next, jumper"
:total="total"
style="height:40px;city-height:40px;"
></el-pagination>
</div> export default class carAcct extends Vue {
private multipleSelection: any = []
private listData: any = []
private currentPage = 1
private total = 0
private pageSize = 20
private TABLEHEIGHT = document.documentElement.clientHeight - 272 private handleSizeChange (e: any) {
this.pageSize = e
this.listPage()
}
private handleCurrentChange (e: any) {
this.currentPage = e
this.listPage()
}
private handleSelectionChange (val: any) {
this.multipleSelection = val
}
}

一、vue+elementUI实现 分页表格前的单选

单选效果图:

主要是使用elementUI提供的table中的toggleRowSelection(row, selected)方法,
  *该方法用于多选表格,切换某一行的选中状态,如果使用了第二个参数,则是设置这一行选中与否(selected 为 true 则选中)

这和上面的多选差不多完全一样,只是在选择方法 handleSelectionChange中加上判断:

1 if (val.length > 1) {
2 (this.$refs.multipleTable as any).toggleRowSelection(val[0], false)
3 val.splice(0, 1)
4 }

特别说明一下:因为我用的TypeScript,而TypeScript 又是强类型检查,所以  this.$refs.multipleTable  改成了  (this.$refs.multipleTable as any),不然会报以下错误:

如果不是使用的TypeScript,可以直接写成以下格式:

 if (val.length > 1) {
this.$refs.multipleTable.toggleRowSelection(val[0], false)
val.splice(0, 1)
}

总代码如下:

<el-table
ref="multipleTable"
:data="listData"
tooltip-effect="dark"
:default-sort="{ prop: 'date', order: 'descending' }"
:stripe="true"
:max-height="TABLEHEIGHT"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" min-width="55"></el-table-column>
<el-table-column label="ID" prop="id" align="left" width="80"></el-table-column> <div class="city-list-body-pagination">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-size="pageSize"
layout="total, prev, pager, next, jumper"
:total="total"
style="height:40px;city-height:40px;"
></el-pagination>
</div> export default class carAcct extends Vue {
private multipleSelection: any = []
private listData: any = []
private currentPage = 1
private total = 0
private pageSize = 20
private TABLEHEIGHT = document.documentElement.clientHeight - 272 private handleSizeChange (e: any) {
this.pageSize = e
this.listPage()
}
private handleCurrentChange (e: any) {
this.currentPage = e
this.listPage()
}
private handleSelectionChange (val: any) {
if (val.length > 1) {
(this.$refs.multipleTable as any).toggleRowSelection(val[0], false)
val.splice(0, 1)
}
this.multipleSelection = val
}
}

3、禁止部分选择

首先我们实现多选: 手动添加一个el-table-column,设type属性为selection即可;然后设置 selectable 属性来决定该行数据是否选中。

<template>
<el-table
ref="multipleTable"
:data="tableData"
tooltip-effect="dark"
style="width: 100%"
@selection-change="handleSelectionChange">
<el-table-column
type="selection"
:selectable="checkSelectable"
width="55">
</el-table-column>
......
</el-table>
</template>

设置禁止选中的条件:

checkSelectable(row) {
return row.date == '2016-05-03'
},

若返回为 true, 则可以选中,否则禁止选中

vue+elementUI实现 分页表格的单选或者多选、及禁止部分选择的更多相关文章

  1. vue+element-ui 实现分页(根据el-table内容变换的分页)

    官方例子 官方提示: 设置layout,表示需要显示的内容,用逗号分隔,布局元素会依次显示.prev表示上一页,next为下一页,pager表示页码列表,除此以外还提供了jumper和total,si ...

  2. php一些单选、复选框的默认选择方法(示例)

    转载 http://www.php.cn/php-weizijiaocheng-360029.html 一. radio和checkbox及php select默认选择的实现代码 1.radio单选框 ...

  3. vue elementui点击表格当前行radio单选选中

    官方文档:https://element.eleme.cn/#/zh-CN/component/radio 参考:https://www.cnblogs.com/steamed-twisted-rol ...

  4. vue+Element-ui实现分页效果

    当我们向后台请求大量数据的时候,并要在页面展示出来,请求的数据可能上百条数据或者更多的时候,并不想在一个页面展示,这就需要使用分页功能来去完成了. 1.本次所使用的是vue2.0+element-ui ...

  5. vue element-ui 做分页功能之封装

    在 vue 项目中的 components 中 创建一个 文件夹,文件夹里创建一个 name(这个名字你随意取).vue <template>   <div class=" ...

  6. vue+element-ui实现分页

    我使用得是el-table+el-pagination来实现的, 话不多说,直接上代码 html代码部分 <!-- table --> <el-table :data="s ...

  7. vue+element-ui 实现分页

    <el-table ref="multipleTable" :data="tableData.slice((currentPage-1)*pagesize,curr ...

  8. vue+element-ui:table表格中的slot 、formatter属性

    slot 插槽,table中表示该行内容以自定义方式展示 :formatter 方法,用来格式化内容 Function(row, column, cellValue, index) html < ...

  9. ElementUI的Table表格添加自定义头CheckBox多选框

    在ElmentUI的Table表格组件中,也许你会使用type为selection值的多选框功能,但是此时设置的label属性不生效,不能设置标题名称:有时候我们的需求就是要添加标题名称,那该如何处理 ...

随机推荐

  1. 微信小程序|小游戏

    [官]小游戏开发 https://developers.weixin.qq.com/minigame/dev/index.html 官网 https://mp.weixin.qq.com 做了4个微信 ...

  2. Visual Studio Installer闪退问题解决方法

    Visual Studio 2019安装推荐的方式是通过官方给的Installer进行的(2017也是同样方法),但是有时会出现在”即将完成…一切即将准备就绪“这个界面闪退的问题,导致软件的安装.卸载 ...

  3. Unity Plugins的使用方法

    一.为插件设置平台的方法 unity5之前,是通过把插件搞到对应目录进行区分平台的(比如在build target是ios平台时只把IOS目录的插件build进去),unity5之后提供了设置平台/c ...

  4. Math Problem(数学)

    链接:https://ac.nowcoder.com/acm/contest/893/C来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K ...

  5. WPF实现手势解锁

    桌面程序的解锁方式一般是账号密码,互联网的可以使用扫码解锁,甚至人脸识别.但扫码需要网络,人脸识别又较复杂.所以就想把安卓常用的手势解锁移植到桌面程序上. 先来张效果图,有兴趣的往下看,没兴趣的打扰了 ...

  6. vant ui TabBar封装

    TabBar.vue基本上是放在App.vue里面,都存在 <template> <div id="app"> <home-tab-bar :tar- ...

  7. 小程序开发-媒体组件image

    image 图片组件,支持 JPG.PNG.SVG.WEBP.GIF 等格式,2.3.0 起支持云文件ID. 所有属性如下: Tips image组件默认宽度320px.高度240px image组件 ...

  8. Zabbix Server宕机报“__zbx_mem_malloc(): out of memory (requested 96 bytes)”

    早上登录Zabbix的时候,发现其提示"Zabbix server is not running: the information displayed may not be current& ...

  9. 判断同名股票是否存在的MyBatis查询函数写法

    在A股中,除非股票退市,六位的股票代号是永不变化的,而名称则可能变化,比如更换主业,更换金主,因经营不善而戴帽等,这时名称都会改变. 因此,从网页上爬取的实时股票信息,需要常常与存在本地数据库里的信息 ...

  10. Combine 框架,从0到1 —— 4.在 Combine 中使用计时器

    本文首发于 Ficow Shen's Blog,原文地址: Combine 框架,从0到1 -- 4.在 Combine 中使用计时器. 内容概览 前言 使用计时器执行周期性的工作 将计时器转换为计时 ...