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

element ui表格手寫拖動排序

這篇具有很好參考價值的文章主要介紹了element ui表格手寫拖動排序。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

效果圖:
element ui表格手寫拖動排序,ui

思路:

重點在于:拖動行到某一位置,拿到這一位置的標識,數(shù)據(jù)插入進這個位置 vueuse的拖拽hooks useDraggable 可以用;html5 drag能拖動行元素;mounsedown、mounsemove時間實現(xiàn)拖拽

頁面html表格代碼

<el-table
                            :data="columnModelList"
                            height="calc(100% - 40px)"
                            stripe
                            border
                            style="width: 100%">
                            <!-- 通過自定義圖標去拖動 -->
                            <el-table-column
                                header-align="center"
                                type="index"
                                align="center"
                                label=""
                                :width="60"
                            >
                                <template #default="{ row, $index }">
                                <span
                                    :class="filedInfoClass['drag-table-item'] + '-' + $index"
                                    @mousedown="dragHandle.dragStart(row, $index, filedInfoClass)"
                                >
                                <img style="cursor: move;width: 30px;height: 30px;" th:src="@{/manager/assets/images/drag_icon.svg}">
                                </span>
                                </template>
                            </el-table-column>
                            <el-table-column
                                prop="title"
                                label="標題"
                                show-overflow-tooltip
                                min-width="192">
                            </el-table-column>
                            <el-table-column
                                prop="productType"
                                label="產(chǎn)品類型"
                                show-overflow-tooltip
                                width="95">
                            </el-table-column>
                            <el-table-column
                                prop="productName"
                                width="243"
                                show-overflow-tooltip
                                label="產(chǎn)品名稱">
                            </el-table-column>
                            <el-table-column
                                prop="version"
                                label="版本號"
                                show-overflow-tooltip
                                width="114">
                            </el-table-column>
                            <el-table-column
                                prop="updateType"
                                label="版本更新類型"
                                show-overflow-tooltip
                                width="140">
                                <template slot-scope="scope">
                                    {{ showText(scope.row) }}
                                </template>
                            </el-table-column>
                            <el-table-column
                                prop="introduction"
                                show-overflow-tooltip
                                width="263"
                                label="簡述">
                            </el-table-column>
                            <el-table-column
                                prop="issueDate"
                                show-overflow-tooltip
                                width="206"
                                label="發(fā)布時間">
                                <template slot-scope="scope">
                                    <span>{{ scope.row.issueDate && ![0, 2, 3].includes(scope.row.status * 1) ? getIssueDate(scope.row.issueDate) : '/' }}</span>
                                </template>
                            </el-table-column>
                            <el-table-column
                                prop="status"
                                show-overflow-tooltip
                                width="100"
                                label="狀態(tài)">
                                <template slot-scope="scope">
                                    <div style="text-align: center;height: 32px;line-height: 32px;">
                                        <span style="color: #262626;background: #EBEDF0;border: 1px solid rgba(102,102,102,0.06);" v-if="scope.row.status * 1 === 0" class="status-box">草稿</span>
                                        <span style="color: #F47D06;background: #FEF4EB;border: 1px solid rgba(244,125,6,0.06);" v-else-if="scope.row.status * 1 === 2" class="status-box">待審核</span>
                                        <span style="color: #E20000;background: #FEEBEB;border: 1px solid rgba(226,0,0,0.06);" v-else-if="scope.row.status * 1 === 3" class="status-box">退回</span>
                                        <span style="color: #E20000;background: #FEEBEB;border: 1px solid rgba(226,0,0,0.06);" v-else-if="scope.row.status * 1 === 4" class="status-box">待發(fā)布</span>
                                        <span style="color: #262626;background: #EBEDF0;border: 1px solid rgba(102,102,102,0.06);" v-else-if="scope.row.status * 1 === 1" class="status-box">已發(fā)布</span>
                                        <span style="color: #E20000;background: #FEEBEB;border: 1px solid rgba(226,0,0,0.06);" v-else="scope.row.status * 1 === 5" class="status-box">已刪除</span>
                                    </div>
                                </template>
                            </el-table-column>
                            <el-table-column
                                fixed="right"
                                label="操作"
                                width="60">
                                <template slot-scope="scope">
                                    <div class="table-button" @click="handleViews(scope.row)">
                                        查看
                                    </div>
                                </template>
                            </el-table-column>
                        </el-table>

在 template 模版中 定義mousedown方法,表示開始拖拽,并拿到記錄拖拽元素標識信息
element ui表格手寫拖動排序,ui

拖拽時采用原生js獲取行維度數(shù)據(jù),設(shè)置 effectAllowed = ‘move’ 表示每行都可以放置
拖動到每一行上時拿到行標識,并動態(tài)插入交換表格數(shù)據(jù),vue通過 diff算法分析,dom變動實現(xiàn)拖動效果
放置時拿到拖動行id ,目標行 id 請求數(shù)據(jù),動態(tài)刷新表格數(shù)據(jù)

在created里面定義拖動方法

const that = this
        that.dragHandle = {
        // 開始拖拽
            dragStart(row, i, filedInfoClass) {
                const dataSetDetail = []
                let dragI = i;  // 拖拽起點
                // 采用原生 js 獲取 第 i 行
                const con = document.querySelector(
                `.el-table__body .row-class-${i}`
                )
                const tbody = document.querySelector(
                `.el-table__body tbody`
                )
                let tr = document.querySelectorAll(
                `.el-table__body tbody tr`
                );
                const dragKey = row.gid;  // 拖拽的元素標識
                if (con) {
                        con.setAttribute('draggable', 'true');

                        con.ondragstart = (ev) => {
                            console.log('start', ev);
                        }
                };

                // 設(shè)置 effectAllowed = 'move' 表示每行都可以放置
                tbody.ondragover = (ev) => {
                    if (ev.dataTransfer) {
                        ev.dataTransfer.effectAllowed = 'move';
                    }
                    ev.preventDefault();
                };
                tbody.ondragenter = (ev) => {
                    if (ev.dataTransfer) {
                        ev.dataTransfer.effectAllowed = 'move';
                    }
                    ev.preventDefault();
                };

                tr.forEach((el, n) => {
                    el.ondragover = that.debounce(
                        () => {
                        // dataSetDetail.value?.columnModelList 表格數(shù)據(jù)
                            const item = that.columnModelList[dragI]
                            // n 移動到 第 n 個
                            // i 從 第 i 個
                            if (n > dragI) {
                                that.columnModelList.splice(n + 1, 0, item);
                                that.columnModelList.splice(dragI, 1);
                            } else if (n < dragI) {
                                const start = n - 1 < 0 ? 0 : n;
                                that.columnModelList.splice(start, 0, item);
                                that.columnModelList.splice(dragI + 1, 1);
                            }
                            dragI = n;
                    },500,that);
                });
                tr = document.querySelectorAll(
                    `.${filedInfoClass['field-info-container']} tbody tr`
                );
                tr.forEach((el) => {
                    el.ondragend = () => {
                    const columns = that.columnModelList || [];
                    const beforeI =
                        dragI + 1 >= columns.length ? -1 : dragI + 1;
                    const columnId = columns[dragI].resourceId || '';
                    const beforeColumnId = columns[beforeI]?.resourceId || null;
                    };
                })
            }
        }

在data中定義樣式對象

filedInfoClass: {
                'field-info-container': 'field-info-container',
                'drag-table-item': 'row-class'
            },

columnModelList是定義在data中的表格數(shù)據(jù)

可以做到拖動一個就掉接口,我這里是拖動完,點保存才將數(shù)據(jù)傳給后臺。,掉接口文章來源地址http://www.zghlxwxcb.cn/news/detail-829980.html

到了這里,關(guān)于element ui表格手寫拖動排序的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • element-ui 中的表格設(shè)置正確的排序以及怎么設(shè)置默認排序

    element-ui 中的表格設(shè)置正確的排序以及怎么設(shè)置默認排序

    本文主要解決兩個問題,第一個,在element-ui中,直接設(shè)置參數(shù)排序,達不到預期效果,預期是按照數(shù)字的大小進行排序;第二個,想對表格中某個字段設(shè)置默認的排序方式 現(xiàn)象: 直接設(shè)置在 el-table-column設(shè)置sortable=true,點擊升序降序,結(jié)果是字符串的排序結(jié)果,不是預期的按

    2024年02月02日
    瀏覽(24)
  • 如何實現(xiàn)element ui中的表格全部數(shù)據(jù)分頁排序

    默認情況下, table表格設(shè)置了sortable是只能當前頁, 數(shù)據(jù)進行排序的, 這顯然是沒有多大意義的 ,那么如何實現(xiàn)全部數(shù)據(jù)分頁排序呢? 首先 ,把sortable 寫成sortable=“custom” 然后,在 el-table標簽中加入 @sort-change=\\\'sortChange\\\' 最后 ,sortChange方法代碼如下: sortChange(val){ ?? ??

    2024年02月11日
    瀏覽(25)
  • vue 實現(xiàn)element-ui 表格的行拖拽排序 (Sortable)

    Sortable它是一個比較簡單好用的拖拽排序工具 1.首先是安裝下載Sortable (npm install?sortablejs --save) 2.在要進行拖拽的頁面引入Sortable (import Sortable from \\\'sortablejs\\\') 3.寫個方法去處理你需要的數(shù)據(jù),這里需要注意一下需要等待元素渲染完成后再執(zhí)行此方法 ?4.處理好數(shù)據(jù)以后再去

    2024年02月11日
    瀏覽(29)
  • element ui el-table sorttable實現(xiàn)表格拖拽排序(vuedraggable)

    element ui el-table sorttable實現(xiàn)表格拖拽排序(vuedraggable)

    如果已經(jīng)安裝了 vuedraggable ,則可以不用安裝 sortablejs

    2024年02月11日
    瀏覽(18)
  • VUE element-ui實現(xiàn)表格動態(tài)展示、動態(tài)刪減列、動態(tài)排序、動態(tài)搜索條件配置、表單組件化。

    VUE element-ui實現(xiàn)表格動態(tài)展示、動態(tài)刪減列、動態(tài)排序、動態(tài)搜索條件配置、表單組件化。

    ? ? 1、本組件支持列表的表頭自定義配置,checkbox實現(xiàn) 2、本組件支持列表列排序,vuedraggable是拖拽插件,上圖中字段管理里的拖拽效果 ,需要的話請自行npm install 3、本組件支持查詢條件動態(tài)配置,穿梭框?qū)崿F(xiàn) https://download.csdn.net/download/askuld/88216937

    2024年01月16日
    瀏覽(41)
  • 【前端】Layui動態(tài)數(shù)據(jù)表格拖動排序

    【前端】Layui動態(tài)數(shù)據(jù)表格拖動排序

    目的:使用Layui的數(shù)據(jù)表格,拖動行進行排序。 使用插件:layui-soul-table 和 Layui 1.layui-soul-table文檔:https://soultable.yelog.org/#/zh-CN/component/start/install 2.layui文檔:Layui table模塊 | 數(shù)據(jù)表格 | datatable - 在線演示 結(jié)合Layui并參看layui-soul-table官方教程,寫的比較詳細頁比較簡單。 實現(xiàn)

    2024年02月10日
    瀏覽(27)
  • 隨手記:使用sortable.js 實現(xiàn)element-ui el-table 表格上下拖拽排序

    需求場景: 表格可以實現(xiàn)上下拖拽row實現(xiàn)新排序 首先,安裝sortable.js ?引入表格排? 全局掛在組件 使用頁面引入 使用sortable.js表格一定要有唯一的row-key,一般綁定的是id,不然拖拽會不生效 data聲明 sortableContainer: null,為的是后面如果有需要可以做銷毀操作 ? 因為我這里是表

    2024年02月22日
    瀏覽(30)
  • web前端之拖拽API、上傳多圖片時拖拽排序、表格行或列拖拽排序、復制元素跨區(qū)域放置、拖放、投擲、若依、vuedraggable、sortablejs、element、plus、vue、ui

    web前端之拖拽API、上傳多圖片時拖拽排序、表格行或列拖拽排序、復制元素跨區(qū)域放置、拖放、投擲、若依、vuedraggable、sortablejs、element、plus、vue、ui

    前言 vue3+element-puls列表行、列拖拽的需求,想找一個成熟的解決方法。但發(fā)現(xiàn)vue3的比較少,所以就把這個分享出來,希望可以幫助到大家。vuedraggable是一款vue3的拖拽插件,基于sortable.js實現(xiàn),可以用來拖拽列表、菜單、工作臺、選項卡等常見的工作場景。安裝的是vuedraggabl

    2024年01月22日
    瀏覽(18)
  • Element UI table 順序拖動

    Element UI table 順序拖動

    使用Sortable.js插件。對element-ui中的el-table進行拖拽行排序。 官網(wǎng): [1] Sortable.js官網(wǎng)配置項說明等 [2] Sortable更多使用示例 一、基本使用 1、安裝 2、引用 3、使用 說明: orderNum :為排序號 handle : 使列表單元中符合選擇器的元素成為拖動的手柄,只有按住拖動手柄才能使列表

    2023年04月21日
    瀏覽(18)
  • vue/Element UI 實現(xiàn)Element UI el-dialog 自由拖動

    vue/Element UI 實現(xiàn)Element UI el-dialog 自由拖動

    前言: 最近有個項目,客戶要求彈窗可拖動,但是由于elemen ui本身的彈窗并沒有拖動的屬性,無法滿足客戶的需求。 于是我百度找到了幾篇文章,終于可以實現(xiàn)客戶的需求! 請往下看↓↓ 一、新建一個目錄:utils 二、創(chuàng)建drag .js文件 三、創(chuàng)建directive.js 文件 四、main.js文件中

    2024年02月02日
    瀏覽(33)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包