Element table使用技巧详解

1、控制table某些行数不显示

  下载附件的需求,有些行有附件,有些没有,所以需要过滤,重点是:Array.filter()使用

<el-card :body-style="{ padding: '20px 10px' }">
    <h5>附件列表</h5>
    <el-table :data="quesObj.filter(item => item.attach)">
        <el-table-column label="附件名称" align="center">
            <template slot-scope="scope">
                <a :download="scope.row.attach" :href="'/api/hbase/readFile?fileName=' + scope.row.attach">{{scope.row.attach}}</a>
            </template>
        </el-table-column>
    </el-table>
</el-card>

2、elementUI的table自定义合计方法

//1、table上添加summary-method自定义计算方法
<el-table 
    class="orderStyle"
    :show-summary = "userInfo && userInfo.roleName === 'user'"
    :summary-method="totalRule"
    ref="order"
    :data="orderData"
    @selection-change="handleSelectionChange">

//2、选择的行数据
handleSelectionChange(rows){
    this.orders = rows
},

//3、合计规则:注意return的是与列对应的数组
totalRule(){
    let sum = 0
    this.orders.forEach(item => {
        sum += item.price
    })
    return ['合计','','','',sum,'']
},

3、elementUi的tabel组件如果要显示合计的话,下面的prop是必须得加的

<el-table-column label="服务价格" prop="service_price">
    <template slot-scope="scope">{{scope.row.service_price}}</template>
</el-table-column>

4、elementUi的tabel组件复选框控制禁止选择

<el-table-column 
type="selection" 
width="55" 
:selectable='checkboxInit'>
</el-table-column>

//methods里
checkboxInit(row,index){
  if (row.withdrawState==2)//这个判断根据你的情况而定
    return 0;//不可勾选,或者是return false/true
  else
    return 1;//可勾选
}

猜你喜欢

转载自www.cnblogs.com/goloving/p/9149975.html