vue 结合原生tabe 渲染表格 实现 固定头部、固定右侧、单选按钮、单元格拖拽监听位置

本文介绍如何利用Vue结合原生table组件,实现固定头部、固定右侧列、单选按钮以及监听单元格拖拽等高级功能,旨在解决在大数据量下el-table可能出现的卡顿问题。
摘要由CSDN通过智能技术生成

1.vue 结合原生tabe 渲染表格 实现 固定头部、固定右侧、单选按钮(避免el-table 数据量大卡顿)

// table.vue
<template>
    <div id="oldTable" v-if="headerData.length && tableData.length">
        <div class="table-scroll-mod" :style="{height: height+ 'px'}">
            <div class="table-scroll-box" :style="{height: height+ 'px'}" ref="tableScrollBox">
                <div class="fixed-head" ref="tableFixedHead">
                    <table>
                        <thead>
                        <tr>
                            <th v-if="checkBox" :width="checkBoxWidth">
                                <div class="te_cell">
                                    <input type="checkbox" v-model="isAllCheck" @click="checkAll" name="table"
                                           value="all"/>
                                </div>
                            </th>
                            <th :width="item.width || 100" v-for="(item, index) in headerCol" :key="index"
                                v-if="item.prop !== 'checkbox'">
                                <div class="te_cell">{
   {
   item.label}}</div>
                            </th>
                        </tr>
                        </thead>
                    </table>
                </div>
                <div class="fixed-right" :class="isMac ? '' : 'fixed-right_h'" ref="tableFixedRight"
                     :style="{width: (headerCol[rightIndex].width || 100) + 'px'}">
                    <table>
                        <thead>
                        <tr>
                            <td :width="headerCol[rightIndex].width">
                                <div class="te_cell">{
   {
   headerCol[rightIndex].label}}</div>
                            </td>
                        </tr>
                        </thead>
                        <tbody>

                        <tr v-for="(item, index) in tableData" :key="index">
                            <td :width="headerCol[rightIndex].width">
                                <div class="te_cell">
                                    <slot name="fixedRight" :row="item"></slot>
                                </div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="fixedTopRight" :style="{width: (headerCol[rightIndex].width || 100) + 'px'}">
                    <span class="te_cell">{
   {
   headerCol[rightIndex].label}}</span>
                </div>
                <table class="table-content__warrp">
                    <thead>
                    <tr>
                        <th :width="item.width" v-for="(item, index) in headerCol" :key="index">
                            <div class="te_cell">{
   {
   item.label}}</div>
                        </th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr v-for="(item, index) in tableData" :key="index">
                        <td :width="checkBoxWidth">
                            <div class="te_cell" v-if="checkBox">
                                <input type="checkbox" name="table" v-model="checkBoxList[index]"
                                       @click="checkItem(item, index)" :value="index"/>
                            </div>
                        </td>
                        <td :width="child.width || 100" v-for="(child, index_c) in headerCol" :key="index_c"
                            v-if="child.prop !== 'checkbox'"
                            :draggable="draggable"
                            @dragstart="onDragstart($event, item, child.prop)"
                            @dragend="onDragend($event)"
                            @dragover="onDragover($event)"
                            @drop="onDrop($event, item, child.prop)">
                            <div class="te_cell" v-if="child.slot">
                                <slot :name="child.slot" :row="item"></slot>
                            </div>
                            <div class="te_cell" v-if="!child.slot">{
   {
   item[child.prop]}}</div>
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</template>
<script type="text/ecmascript-6">
    const IS_MAC = function () {
   
        return /macintosh|mac os x/i.test(navigator.userAgent);
    }();

    function throttle(delay, noTrailing, callback, debounceMode) {
   
        var timeoutID;
        var cancelled = false;
        var lastExec = 0;

        function clearExistingTimeout() {
   
            if (timeoutID) {
   
                clearTimeout(timeoutID);
            }
        }

        function cancel() {
   
            clearExistingTimeout();
            cancelled = true;
        }

        if (typeof noTrailing !== 'boolean') {
   
            debounceMode = callback;
            callback = noTrailing;
            noTrailing =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值