欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

element的el-table自定義最后一行的實現代碼

 更新時間:2024年03月26日 14:47:37   作者:暴富的im  
最后一行要顯示一些其他結果,用的是element? ui 自帶的數據總計的屬性;返回一個數組,會按下標進行展示,這篇文章主要介紹了element的el-table自定義最后一行的實現代碼,需要的朋友可以參考下

element的el-table自定義最后一行

場景:

最后一行要顯示一些其他結果,用的是element  ui 自帶的數據總計的屬性;返回一個數組,會按下標進行展示。

代碼:

  <el-table 
       :summary-method="getSummaries"
        show-summary 
       :data="tableData"
       stripe
        style="width: 50% ;margin-top: 20px;font-size: 15px;">
    <el-table-column prop="date" label="日期" width="180">
    </el-table-column>
      <el-table-column prop="name" label="姓名" width="180">
        </el-table-column>
       <el-table-column prop="address" label="地址">
        </el-table-column>
        </el-table>
重點在于getSummaries這個自定義的方法,返回一個數組即可以顯示
    getSummaries(param) {
            const { columns } = param
            const sums = []
            columns.forEach((column, index) => {
                switch (index) {
                    case 0:
                        sums[index] = '是否通過'
                        break
                    case 1:
                        sums[index] = 'erewrwr'
                        break
                    case 2:
                        sums[index] = 'erewrwr'
                        break
                    case 3:
                        sums[index] = 'erewrwr'
                        break
                }
            })
            return sums
        },

element-ui中的el-table底部固定指定行

1,固定一行合計的情況

https://element.eleme.cn/#/zh-CN/component/table

直接使用官方文檔上的summary-method

2,固定指定行或者多行

使用樣式去固定

例子:(計算列表數據的平均值,最大值,最小值并固定底部)

1,計算數據的值

protected calcData(data: any) {
        const sums: any = {};
        const max: any = {};
        const min: any = {};
        const columns = this.$refs["coverTable"]?.columns;
        columns.forEach((column: any, index: number) => {
            if (index === 0) {
                sums[column.property] = "平均值";
                max[column.property] = "最大值";
                min[column.property] = "最小值";
                return;
            }
            const values = data.map((item: any) => Number(item[column.property]));
            if (!values.every((value: any) => isNaN(value))) {
                // 總和
                sums[column.property] = values.reduce((prev: any, curr: any) => {
                    const value = Number(curr);
                    if (!isNaN(value)) {
                        return prev + curr;
                    } else {
                        return prev;
                    }
                }, 0);
                // 最大值
                max[column.property] = values.reduce((prev: any, curr: any) => {
                    const value = Number(curr);
                    if (!isNaN(value) && curr > prev) {
                        return curr;
                    } else {
                        return prev;
                    }
                });
                // 最小值
                min[column.property] = values.reduce((prev: any, curr: any) => {
                    const value = Number(curr);
                    if (!isNaN(value) && curr > prev) {
                        return prev;
                    } else {
                        return curr;
                    }
                });
            } else {
                sums[column.property] = "N/A";
                max[column.property] = "N/A";
                min[column.property] = "N/A";
            }
        });
        const average: any = {};
        for (const i in sums) {
            if (!isNaN(sums[i])) {
                average[i] = (sums[i] / data.length).toFixed(3);
            } else {
                average[i] = sums[i];
            }
        }
        if (this.tableData.length > 0) this.tableData.push(average, max, min);
    }

2,對要固定的三行設置class

// 行固定
    tableRowClassName(params: any) {
        const { row, rowIndex } = params;
        row.index = rowIndex;
        // 最后三行固定
        if (rowIndex + 1 === this.tableData.length - 2) {
            return `tr-fixed fixed-row2`;
        } else if (rowIndex + 1 === this.tableData.length - 1) {
            return `tr-fixed fixed-row1`;
        } else if (rowIndex + 1 === this.tableData.length) {
            return `tr-fixed fixed-row`;
        } else {
            return ``;
        }
    }

3, 樣式控制

.el-table {
    .tr-fixed{
        display: table-row;
        position: sticky;
        bottom: 0;
        width: 100%;
        td {
            border: 1px solid #f3f5fa;
            background: #fff;
        }
    }
    .fixed-row{
        bottom: 0;
    }
    .fixed-row1{
        bottom: 0.5rem;
    }
    .fixed-row2{
        bottom: 1rem;
    }
}

4,效果

到此這篇關于element的el-table自定義最后一行的文章就介紹到這了,更多相關element的el-table自定義最后一行內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Vuex的使用及知識點筆記

    Vuex的使用及知識點筆記

    這篇文章主要介紹了Vuex的使用及知識點筆記,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 通過npm或yarn自動生成vue組件的方法示例

    通過npm或yarn自動生成vue組件的方法示例

    這篇文章主要介紹了通過npm或yarn自動生成vue組件的方法示例,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-02-02
  • vue實現手機號碼的校驗實例代碼(防抖函數的應用場景)

    vue實現手機號碼的校驗實例代碼(防抖函數的應用場景)

    這篇文章主要給大家介紹了關于vue實現手機號碼的校驗的相關資料,主要是防抖函數的應用場景,文中通過示例代碼介紹的非常詳細,對大家學習或者使用vue具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-09-09
  • vue緩存之keep-alive的理解和應用詳解

    vue緩存之keep-alive的理解和應用詳解

    這篇文章主要介紹了vue緩存之keep-alive的理解和應用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-11-11
  • Vue3狀態(tài)管理之Pinia的入門使用教程

    Vue3狀態(tài)管理之Pinia的入門使用教程

    Pinia是Vue.js的輕量級狀態(tài)管理庫,比起vue3中的Vuex狀態(tài)管理,pinia更輕量,更容易使用,下面這篇文章主要給大家介紹了關于Vue3狀態(tài)管理之Pinia的入門使用教程,需要的朋友可以參考下
    2022-04-04
  • iview實現select tree樹形下拉框的示例代碼

    iview實現select tree樹形下拉框的示例代碼

    這篇文章主要介紹了iview實現select tree樹形下拉框的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2018-12-12
  • 解決vue組件沒顯示,沒起作用,沒報錯,但該顯示的組件沒顯示問題

    解決vue組件沒顯示,沒起作用,沒報錯,但該顯示的組件沒顯示問題

    這篇文章主要介紹了解決vue組件沒顯示,沒起作用,沒報錯,但該顯示的組件沒顯示問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • 詳解vue-cli快速構建vue應用并實現webpack打包

    詳解vue-cli快速構建vue應用并實現webpack打包

    這篇文章主要介紹了詳解vue-cli快速構建vue應用并實現webpack打包,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-12-12
  • 探索Vue如何高效構建可復用組件

    探索Vue如何高效構建可復用組件

    Vue.js作為現代前端開發(fā)中的佼佼者,其組件系統(tǒng)是構建高效、靈活和可擴展用戶界面的關鍵,本文帶大家深度探索?Vue.js?組件的核心奧義,感興趣的小伙伴可以了解下
    2024-12-12
  • vue全局方法plugins/utils的實現示例

    vue全局方法plugins/utils的實現示例

    很多時候我們會在全局調用一些方法,本文主要介紹了vue全局方法plugins/utils的實現示例,具有一定的參考價值,感興趣的可以了解一下
    2024-07-07

最新評論