国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

element中Table表格控件單選、多選功能進一步優(yōu)化

這篇具有很好參考價值的文章主要介紹了element中Table表格控件單選、多選功能進一步優(yōu)化。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、代碼實現(xiàn)

1、 父組件

<template>
   <div>
       <!-- 用戶選擇嵌套彈框 -->
		<el-dialog :close-on-click-modal="false" :close-on-press-escape="false" title="選擇人員" :visible.sync="open"
			width="80%" append-to-body :show-close="false">
			<TableList :open="open" :dataList="dataList" @submitForm="submitForm" @cancel="cancel"></TableList>
		</el-dialog>
   </div>
</template>

<script>
import TableList from '@/components/table-list'
export default {
    name: 'TablePage5',
    components:{
        TableList,
    },
    props: {
      
    },
    data() {
        return {
            open:true,
            dataList:[ {
                        userId: 3,
                        userName: '王五'
                    },],
        }
    },
    watch: {
       
    },
    methods: {
        // 取消
		cancel() {
			// this.open = false
            // .............
		},
		// 確認
		submitForm(checkIds) {
			console.log(checkIds, 'checkId獲取到')
            // .........
		},

    }
}
</script>

<style>

</style>

2、子組件(彈框)

<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
            <el-form-item label="搜索" prop="search">
                <el-input v-model="queryParams.search" placeholder="請輸入" clearable size="small" style="width: 200px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery('queryForm')">搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery('queryForm')">重置</el-button>
            </el-form-item>

        </el-form>
        <el-table v-loading="loading" :data="userList" max-height="400" ref="multipleTable" @select="selectRow"
            @select-all="selectAll" :header-cell-class-name="cellClass" :row-key="row => {
                return row.userId
            }
                ">
            <!-- reserve-selection="true" 僅對 type=selection 的列有效,類型為 Boolean,為 true 則會在數(shù)據(jù)更新之后保留之前選中的數(shù)據(jù)(需指定 row-key) -->
            <el-table-column type="selection" width="50" align="center" :reserve-selection="true" :selectable="selected" />
            <el-table-column type="index" width="100" :index="indexMethod" label="序號">
            </el-table-column>
            <el-table-column label="姓名" align="center" prop="userName" :show-overflow-tooltip="true" />
        </el-table>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryParams.pageNum" :page-sizes="[2, 5, 10, 15]" :page-size="queryParams.pageSize"
            layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
        <!-- <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" :autoScroll="false" /> -->
        <div class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="submitForm">確 定</el-button>
        </div>
    </div>
</template>

<script>
// import { listPeople } from '@/api/manager/peopleList'
export default {
    name: 'TablePage5',
    props: {
        open: {
            type: Boolean,
            default: true
        },
        // 默認選中的數(shù)據(jù)
        dataList: {
            type: Array,
            default: () => {
                return []
            }
        },
        // 默認為0多選, 傳遞1單選
        type: {
            type: Number,
            default: 0
        }
    },
    data() {
        return {
            // 用戶查詢參數(shù)
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                search: ''
            },
            loading: false,
            // 用戶列表(所有的用戶數(shù)據(jù))
            userList: [
                {
                    userId: 1,
                    userName: '張三'
                },
                {
                    userId: 2,
                    userName: '李四'
                },
                {
                    userId: 3,
                    userName: '王五'
                },
                {
                    userId: 4,
                    userName: '測試1'
                },
                {
                    userId: 5,
                    userName: '測試2'
                },
                {
                    userId: 6,
                    userName: '測試3'
                },
            ],
            // 用戶總數(shù)
            total: 0,
            // 全選按鈕隱藏
            DisableSelection: false,
            // 選中的人員列表
            checkList: [],
            // 選中的人員Id列表
            checkIds: []
        }
    },
    watch: {
        // 判斷彈框是否顯示
        open: {
            handler(val) {
                if (val) {
                    this.getList()
                }
            },
            immediate: true
        },
        // 父組件傳遞過來的之前已經(jīng)選中的數(shù)據(jù)
        dataList: {
            handler(list) {
                this.checkList = list
                if(list){
                    this.checkIds = list.map(item=>item.userId)
                }
            },
            immediate: true,
            deep: true
        }
    },
    methods: {
        // 分頁相關(guān)
        indexMethod(index) {
            // this.pageNum當(dāng)前頁碼 // this.pageSize 每頁條數(shù)
            return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
        },
        // 人員列表
        getList() {
            // 根據(jù)實際需求,調(diào)用對應(yīng)接口...........
            // this.loading = true
            // listPeople(this.queryParams)
            //     .then(res => {
            //         console.log(res, '人員列表')
            //         this.userList = res.rows
            //         this.total = res.total
            //         this.loading = false
            //         數(shù)據(jù)回顯
            //         this.selectedRecords()
            //     }).catch(err => {
            //         console.log(err)
            //         this.loading = false
            //     })

            // 數(shù)據(jù)回顯
            this.selectedRecords()
        },
        // 數(shù)據(jù)回顯 (之前選中的數(shù)據(jù),和全部人員數(shù)據(jù)之間判斷,如果userId相同,就表示選中,默認復(fù)選框選中)
        // toggleRowSelection 用于多選表格,切換某一行的選中狀態(tài),如果使用了第二個參數(shù),則是設(shè)置這一行選中與否(selected 為 true 則選中)
        selectedRecords() {
            console.log(this.checkList, '數(shù)據(jù)回顯')
            let that = this
            this.$nextTick(() => {
                this.userList.forEach((row) => {
                    this.checkList.forEach((child) => {
                        if (row.userId == child.userId) {
                            that.$refs.multipleTable.toggleRowSelection(row)
                        }
                    })
                })
            })
        },
        // 分頁相關(guān)
        handleSizeChange(val) {
            console.log(`每頁 ${val} 條`);
            this.queryParams.pageSize = val;
            this.getList()
        },
        handleCurrentChange(val) {
            console.log(`當(dāng)前頁: ${val}`);
            this.queryParams.pageNum = val;
            this.getList()
        },
        // 選擇人員彈框
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        // 選擇人員重置
        resetQuery(queryForm) {
            this.$refs[queryForm].resetFields()
            this.queryParams.pageNum = 1
            this.getList()
        },

        // 全選:list所有選中的數(shù)據(jù)組成的列表
        selectAll(list) {
            console.log('全選', list)
            // list為空,表示全不選
            if (!list.length) { // 全不選
                // 將當(dāng)前頁表格的數(shù)據(jù)循環(huán)判斷是否存在在checkList中,存在就刪除
                this.userList.forEach((item) => {
                    this.checkList.forEach((child, key) => {
                        if (item.userId == child.userId) {
                            this.checkList.splice(key, 1)
                            this.checkIds.splice(key, 1)
                        }
                    })
                })
            } else { // 全選
                // 循環(huán)list,將不存在的值加上,已經(jīng)存在的就不加了
                list.map((item) => {
                    if (this.checkIds.indexOf(item.userId) == -1) {
                        this.checkList.push(item)
                        this.checkIds.push(item.userId)
                    }
                })
            }
        },
        // 單選 list所有選中的數(shù)據(jù)組成的列表,  row當(dāng)前選中或者取消選中的數(shù)據(jù)對象
        selectRow(list, row) {
            console.log('表格單選', list, row)
            let rowId = row.userId
            // 判斷當(dāng)前選項是否已經(jīng)選擇過了, -1表示不存在,沒有選擇過,  其余則是選擇過了
            let isExist = -1
            this.checkList.forEach((item, index) => {
                if (row.userId == item.userId) {
                    isExist = index
                }
            })
            // row.id不存在在list中的時候,說明是取消勾選,undefined表示去除勾選
            let isDel = list.find(item => {
                return item.userId == rowId
            }) == undefined
            if (isDel) { //取消勾選
                // 去除,存在就刪除
                if (isExist != -1) {
                    this.checkList.splice(isExist, 1)
                    this.checkIds.splice(isExist, 1)
                }
            } else { // 勾選
                // 添加
                if (isExist == -1) {
                    this.checkList.push(row)
                    this.checkIds.push(row.userId)
                }
            }
        },
        // 選擇人員確認
        // clearSelection 用于多選表格,清空用戶的選擇
        submitForm() {
            let list = []
            this.checkList.map(item => {
                list.push(item.userId)
            })
            this.checkIds = list
            // 去重
            this.checkIds = [... new Set(this.checkIds)]
            // console.log(this.checkList,'this.checkList')
            // console.log(this.checkIds,'this.checkIds')
            this.$emit('submitForm', this.checkIds)
            // 清除復(fù)選框
            this.$refs.multipleTable.clearSelection()
           
        },
        // 取消按鈕
        cancel() {
            this.$emit('cancel')
            // 清除復(fù)選框
            this.$refs.multipleTable.clearSelection()
        },
        // 超過1個人禁止選擇 (當(dāng)type為1時候,也就是單選時候)
        selected(row) {
            // 限制邏輯,返回 true 則為可勾選,反之則禁止勾選
            let judge = true
            if (this.checkList.length == 1 && this.type == 1) { // 單選
                judge = this.checkList.some(item => {
                    return item.userId == row.userId
                })
            }
            return judge
        },
        // 全選禁用 (當(dāng)type為1時候,是單選,故全選按鈕禁用)
        // 配合樣式使用
        cellClass() {
            if (this.type == 1) {
                return 'DisableSelection'
            }
        }

    }
}
</script>

<style>
.dialog-footer {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 50px;
}

.el-table .DisableSelection .cell .el-checkbox__inner {
    display: none;
    position: relative;
}

.el-table .DisableSelection .cell:before {
    content: '';
    position: absolute;
}
</style>

二、效果圖

element中Table表格控件單選、多選功能進一步優(yōu)化,Element,windows,前端,javascript,elementui
element中Table表格控件單選、多選功能進一步優(yōu)化,Element,windows,前端,javascript,elementui文章來源地址http://www.zghlxwxcb.cn/news/detail-807190.html

到了這里,關(guān)于element中Table表格控件單選、多選功能進一步優(yōu)化的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Element UI 表格單選、多選情景

    Element UI 表格單選、多選情景

    最近在使用Element UI編寫簡單前端頁面時會遇到需要對表格進行選擇操作的場景。在網(wǎng)絡(luò)上面查詢資料時發(fā)現(xiàn)實現(xiàn)方式多的看花眼,索性自己總結(jié)一個。 話不多說,搬代碼來看看~ 單選: 從單選這一塊需求來看,至少滿足下面兩點才能算是完成: 全選框的點擊只能取消其他

    2024年02月11日
    瀏覽(17)
  • el-table 多選框改成單選框(el-table單選功能)

    今天,寫項目時,有一個table作為篩選的載體,需要選中table里面的一條數(shù)據(jù),我想了一下,用table里面的selection功能,實現(xiàn)單選功能。

    2024年02月16日
    瀏覽(25)
  • vue使用Element UI時,el-table表格整行操作單選

    vue使用Element UI時,el-table表格整行操作單選

    需求:表格復(fù)選修改為單選,只可選擇一個;不滿足條件的不可勾選;可進行整行操作 注意使用的方法. 需求由復(fù)選改為單選后, 左上角全選框要進行隱藏 ,復(fù)選框也變成單選框,這里是通過css樣式進行調(diào)整的 勾選復(fù)選框的select和整行操作的row-click可以共用同一個方法,

    2024年02月14日
    瀏覽(26)
  • Element Ui 實現(xiàn)表格單選功能

    今天碰到一個需求,把element-ui中的table多選框改成單選框,實現(xiàn)單選功能 話不多說,直接上代碼 如果這篇文章對您有用的話,記得一鍵三連 !??

    2024年02月11日
    瀏覽(15)
  • element中table多選功能禁止選擇某一項

    element中table多選功能禁止選擇某一項

    element-ui中的table的多選很好用,但是如果其中某一項禁止選擇,該怎樣操作呢 在官方文檔中,有一個這樣的屬性,可以控制是否禁止選擇

    2024年02月13日
    瀏覽(15)
  • element ui el-table分頁多選功能

    selection-change:當(dāng)選擇項發(fā)生變化時會觸發(fā)該事件(當(dāng)分頁切換時,選中的數(shù)據(jù)都會自動清空)

    2024年02月09日
    瀏覽(20)
  • vue使用Element UI時,el-table表格整行操作單選禁選并隱藏全選框

    vue使用Element UI時,el-table表格整行操作單選禁選并隱藏全選框

    需求:表格復(fù)選修改為單選,只可選擇一個;不滿足條件的不可勾選;可進行整行操作 注意使用的方法. 需求由復(fù)選改為單選后, 左上角全選框要進行隱藏 ,復(fù)選框也變成單選框,這里是通過css樣式進行調(diào)整的 勾選復(fù)選框的select和整行操作的row-click可以共用同一個方法,

    2024年02月13日
    瀏覽(23)
  • element ui el-table分頁多選功能失效

    編寫 項目是遇到一個坑: selection-change :當(dāng)選擇項發(fā)生變化時會觸發(fā)該事件(當(dāng)分頁切換時,選中的數(shù)據(jù)都會自動清空) 一、在el-table中 二、在el-table-column中 添加上述刷新重試即可

    2024年04月23日
    瀏覽(32)
  • Android之 日歷單選多選控件

    Android之 日歷單選多選控件

    一,效果圖 1.1 單選 ?2.2 多選 二 實現(xiàn)思路 2.1 數(shù)據(jù)來源,利用原生日歷Calendar,獲取從本月開始的往后一年的日期,遍歷月數(shù)添加全部天數(shù)據(jù) 2.2 添加公立,農(nóng)歷,節(jié)氣數(shù)據(jù)。下面只是節(jié)假日的判斷。 2.3 控件,可以用兩層Recycleview,但最好不要這樣做,嵌套體驗是非常差的,

    2024年02月10日
    瀏覽(25)
  • element-ui中的el-table實現(xiàn)分頁多選功能

    selection-change事件:當(dāng)選擇項發(fā)生變化時會觸發(fā)該事件(當(dāng)分頁切換時,選中的數(shù)據(jù)都會自動清空) 鏈接: https://blog.csdn.net/qq_36157085/article/details/122922678

    2024年02月17日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包