赞
踩
1、需要先声明一个ref变量,并赋值给el-table
2、通过el-table提供的getSelectionRows()函数获取选中的"行对象"数据集
const tableRef = ref();
const selectedAry = tableRef.value.getSelectionRows();
console.log(selectedAry);
<el-table :data="expandAttribute" style="width: 100%">
<el-table-column prop="name" label="属性分类" />
<el-table-column prop="state" label="属性名称" />
<el-table-column prop="city" label="属性编码" />
<el-table-column prop="address" label="属性值" />
<el-table-column>
<template #header>
<span>操作</span>
<el-icon><CirclePlus /></el-icon>
</template>
</el-table-column>
</el-table>
<el-table :data="form.cargoList" :cell-style="tableStyle.cellStyle" :header-cell-style="tableStyle.headerCellStyle" height="300"> <el-table-column type="index" label="序号" width="60" /> <el-table-column prop="spuId" show-overflow-tooltip v-if="false" /> <el-table-column label="物料名称"> <template v-slot="scope"> <el-tree-select v-model="scope.row.skuId" :data="spuLinkTree" :render-after-expand="false" placeholder="请选择物料" @change="selectSku(scope.row)" /> </template> </el-table-column> <el-table-column label="货物数量"> <template v-slot="scope"> <el-input v-model="scope.row.soQty" placeholder="请输入货物数量" /> </template> </el-table-column> <el-table-column label="操作" width="150"> <template #default="scope"> <el-button icon="delete" text type="primary" @click="handleDelete([scope.row.$index])">删除</el-button> </template> </el-table-column> </el-table>
无论在table中勾选几次数据,都只能选中一条。
<el-table :data="tableData" style="width: 100%; margin-bottom: 20px; height: 300px" border ref="chooseSkuTableRef" @select="handleSelectionChange" > <el-table-column type="selection" width="40" align="center" /> <el-table-column prop="skuCode" label="物料编码" /> <el-table-column prop="skuName" label="物料名称" /> </el-table> //列表复选框点击事件(限制列表只能选择一条数据) const handleSelectionChange = (selection, row) => { // 判断长度大于1 if (selection.length > 1) { // shift() 方法用于把数组的第一个元素从其中删除,并返回第一个元素的值。 // 该方法不创建新数组,而是直接修改原有的 arrayObject。 let del_row = selection.shift(); // 其余的都不选中 chooseSkuTableRef.value.toggleRowSelection(del_row, false); } };
需求是“el-table表头的全选框禁止使用,但是还不能隐藏”
el-table标签中加入@select-all=“selectAll”
<el-table :data="tableData" style="width: 100%; margin-bottom: 20px; height: 300px" border ref="chooseSkuTableRef" @select="handleSelectionChange" @select-all="selectAll" > //禁用el-table的表头全选功能 const selectAll = () => { chooseSkuTableRef.value.clearSelection(); };
:header-cell-style=“{‘text-align’:‘center’}”
<el-table
height="90%"
class="sa-table"
:data="currentTableData"
:header-cell-style="{ 'text-align': 'center' }"
row-key="orderNo"
@selection-change="handleSelectionChange"
stripe
>
normalTable.value.toggleAllSelection();
<el-table-column prop="orderNo" label="补货日期">
<template #default="scope">
<div>{{ scope.row.conditionTime?.join('~') || '-' }}</div>
</template>
</el-table-column>
需要在el-table上添加 @row-click="handleRowClick"事件
代码见下方
<el-table
:data="goodsList"
@row-click="handleRowClick"
ref="goodsTableRef"
>
<el-table>
const goodsTableRef = ref();
const handleRowClick = (row) => {
goodsTableRef.value.toggleRowSelection(row);
};
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。