Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

求一个支持treeTable单元格合并的插件 #1709

Open
4 tasks done
zzlatm opened this issue Mar 19, 2024 · 3 comments
Open
4 tasks done

求一个支持treeTable单元格合并的插件 #1709

zzlatm opened this issue Mar 19, 2024 · 3 comments
Labels
feature 功能请求 Feature Request

Comments

@zzlatm
Copy link

zzlatm commented Mar 19, 2024

议题条件

  • 我确认已查看官方使用文档:https://layui.dev ,但没有找到相关解决方案。
  • 我确认已在 Issues 中搜索过类似的问题,但没有找到相关解决方案。
  • 我已仔细阅读: 🍀 Layui Issue 贡献指南

议题类型

功能请求

使用版本

v2.9.6

问题描述

如题,网上找的单元格合并插件只支持tree,在treeTable下会出错,比如这个https://github.com/yelog/layui-table-merge
急用,不知哪位大神能帮忙,万分感谢!

业务代码

/**
 * Created by YujieYang.
 * @name:  子表格扩展
 * @author: 杨玉杰
 * @version 1.0
 */
layui.define(['table'], function (exports) {

    var $ = layui.jquery;

    // 封装方法
    var mod = {
        /**
         * 渲染入口
         * @param myTable
         */
        render: function (myTable) {
            var tableBox = $(myTable.elem).next().children('.layui-table-box'),
                $main = $(tableBox.children('.layui-table-body').children('table').children('tbody').children('tr').toArray().reverse()),
                $fixLeft = $(tableBox.children('.layui-table-fixed-l').children('.layui-table-body').children('table').children('tbody').children('tr').toArray().reverse()),
                $fixRight = $(tableBox.children('.layui-table-fixed-r').children('.layui-table-body').children('table').children('tbody').children('tr').toArray().reverse()),
                cols = myTable.cols[0], mergeRecord = {};

            for (let i = 0; i < cols.length; i++) {
                var item3 = cols[i], field=item3.field;
                if (item3.merge) {
                    var mergeField = [field];
                    if (item3.merge !== true) {
                        if (typeof item3.merge == 'string') {
                            mergeField = [item3.merge]
                        } else {
                            mergeField = item3.merge
                        }
                    }
                    mergeRecord[i] = {mergeField: mergeField, rowspan:1}
                }
            }

            $main.each(function (i) {

                for (var item in mergeRecord) {
                    if (i==$main.length-1 || isMaster(i, item)) {
                        $(this).children('[data-key$="-'+item+'"]').attr('rowspan', mergeRecord[item].rowspan).css('position','static');
                        $fixLeft.eq(i).children('[data-key$="-'+item+'"]').attr('rowspan', mergeRecord[item].rowspan).css('position','static');
                        $fixRight.eq(i).children('[data-key$="-'+item+'"]').attr('rowspan', mergeRecord[item].rowspan).css('position','static');
                        mergeRecord[item].rowspan = 1;
                    } else {
                        $(this).children('[data-key$="-'+item+'"]').remove();
                        $fixLeft.eq(i).children('[data-key$="-'+item+'"]').remove();
                        $fixRight.eq(i).children('[data-key$="-'+item+'"]').remove();
                        mergeRecord[item].rowspan +=1;
                    }
                }
            })

            function isMaster (index, item) {            	
                var mergeField = mergeRecord[item].mergeField;
                var dataLength = layui.table.cache[myTable.id].length;
                for (var i=0; i<mergeField.length; i++) {

                    if (layui.table.cache[myTable.id][dataLength-2-index][mergeField[i]]
                        !== layui.table.cache[myTable.id][dataLength-1-index][mergeField[i]]) {
                        return true;
                    }
                }
                return false;
            }

        }
    };

    // 输出
    exports('tableMerge', mod);
});


截图补充

No response

浏览器

EDGE

演示地址

No response

友好承诺

  • 我承诺将本着相互尊重、理解和友善的态度进行交流,共同维护 Layui 良好的社区氛围。
@Sight-wcg Sight-wcg added the feature 功能请求 Feature Request label Mar 19, 2024
@hulang
Copy link

hulang commented Mar 20, 2024

点进来,居然是,[layui-table-merge](https://github.com/yelog/layui-table-merge)是我们:叶落阁主 插件牛P。。就是最近我们:阁主,太忙,没有更新layui-soul-table

@zzlatm
Copy link
Author

zzlatm commented Mar 20, 2024

点进来,居然是,[layui-table-merge](https://github.com/yelog/layui-table-merge)是我们:叶落阁主 插件牛P。。就是最近我们:阁主,太忙,没有更新layui-soul-table

正是,我跑到他的地盘去留言,没回信,人家几年前的留言都没回。。。

@zzlatm
Copy link
Author

zzlatm commented Apr 13, 2024

其实目前面临的主要问题是:当treeTable的节点展开后,插件tableMerge合并会出错,如果能解决这个问题,那其它就不是问题。因为在treeTable的收缩状态,插件的合并单元格功能是正常工作的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 功能请求 Feature Request
Projects
None yet
Development

No branches or pull requests

3 participants