博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
基于EasyUi的datagrid合并单元格JS写法
阅读量:4922 次
发布时间:2019-06-11

本文共 6095 字,大约阅读时间需要 20 分钟。

$('#dg').datagrid({            width: 'auto',            height: 'auto',            scrollbarSize: 0,            queryParams: {},             url: 'kkkk',            columns: [[                { field: 'bh', title: '编号', width: 100, sortable: false },                { field: 'mc', title: '名称', width: 120, sortable: false },                { field: 'zf', title: '总分', width: 40, sortable: false }            ]],            nowrap: false,            fitColumns: false,            striped: true,            rownumbers: false, //行号            singleSelect: false, //是否单选             onLoadError: function (e) {                $.messager.alert("提示", "加载失败", "error");            },            onLoadSuccess: function (data) {                var cells = ["kc", "uu"];                mergeCells('dg', data, cells);                                });            }        });   //第一种//dg:datagrid的id;data:onLoadSuccess: function (data){}中的data;cellnames:合并的列,var cells = ["ku", "uu"];function mergeCells(dg, data, cellnames) {    for (var i = 0; i < cellnames.length; i++) {        var cellname = cellnames[i];        var merges = [];        for (var r = 0; r < data.rows.length; r++) {            var row = data.rows[r];            var mergeinfo = new Object();            var nr = row[cellname];            var rowspan = 1;            for (var r1 = r + 1; r1 < data.rows.length; r1++) {                var row1 = data.rows[r1];                var nr1 = row1[cellname];                 if (nr1 && nr1 == nr && nr1 != "") {                    mergeinfo.index = r;                    rowspan++;                    mergeinfo.rowspan = rowspan;                }                else {                    if (rowspan > 1) {                        merges.push(mergeinfo);                        r = r1 - 1;                    }                    break;                }                if (r1 == data.rows.length - 1) {                    if (rowspan > 1) {                        merges.push(mergeinfo);                        r = r1 - 1;                    }                }            }        }        for (var j = 0; j < merges.length; j++) {            $('#' + dg).datagrid('mergeCells', {                index: merges[j].index,                field: cellname,                rowspan: merges[j].rowspan            });        }    }}   //第二种 function mergeCells_table(dg, data, cellnames) {    var table = document.getElementById(dg);    for (var i = 0; i < cellnames.length; i++) {        var cellname = cellnames[i];        var merges = [];        for (var r = 0; r < data.rows.length; r++) {            var row = data.rows[r];            var mergeinfo = new Object();            var nr = row[cellname];            var rowspan = 1;            for (var r1 = r + 1; r1 < data.rows.length; r1++) {                var row1 = data.rows[r1];                var nr1 = row1[cellname];                 if (nr1 && nr1 == nr && nr1 != "") {                    mergeinfo.index = r;                    rowspan++;                    mergeinfo.rowspan = rowspan;                    table.rows[r + 1].cells[i].rowSpan = rowspan;                    table.rows[r1 + 1].cells[i].style.display = "none";                }                else {                    if (rowspan > 1) {                        merges.push(mergeinfo);                        r = r1 - 1;                    }                    break;                }                if (r1 == data.rows.length - 1) {                    if (rowspan > 1) {                        merges.push(mergeinfo);                        r = r1 - 1;                    }                }            }        }//        for (var j = 0; j < merges.length; j++) {//            $('#' + dg).datagrid('mergeCells', {//                index: merges[j].index,//                field: cellname,//                rowspan: merges[j].rowspan//            });//        }    }}
$('#dg').datagrid({            width: '100%',            height: '300',            queryParams: {},            loadMsg: '正在加载....',            columns: [[                 { field: 'bh', title: '编号', width: 100, sortable: false },                { field: 'mc', title: '名称', width: 120, sortable: false },                { field: 'zf', title: '总分', width: 40, sortable: false }            ]],            pagination: false, //分页控件             fitColumns: true,            striped: true,            rownumbers: false, //行号            singleSelect: true, //是否单选             onLoadSuccess: function (data) {                var cellcomp = 'bh';                var cells = ['mc', 'zf'];                mergeCells_New('dg', data, cellcomp, cells);            }        });   //dg:datagrid的id;data:onLoadSuccess: function (data){}中的data;cellcomp:列相同;cellnames:合并的列,var cells = ["ku", "uu"];//cellcomp列相同,cellnames合并function mergeCells_New(dg, data, cellcomp, cellnames) {    var merges = [];    for (var r = 0; r < data.rows.length; r++) {        var row = data.rows[r];        var mergeinfo = new Object();        var nr = row[cellcomp];        var rowspan = 1;        for (var r1 = r + 1; r1 < data.rows.length; r1++) {            var row1 = data.rows[r1];            var nr1 = row1[cellcomp];             if (nr1 && nr1 == nr && nr1 != "") {                mergeinfo.index = r;                rowspan++;                mergeinfo.rowspan = rowspan;            }            else {                if (rowspan > 1) {                    merges.push(mergeinfo);                    r = r1 - 1;                }                break;            }            if (r1 == data.rows.length - 1) {                if (rowspan > 1) {                    merges.push(mergeinfo);                    r = r1 - 1;                }            }        }    }    for (var i = 0; i < cellnames.length; i++) {        var cellname = cellnames[i];        for (var j = 0; j < merges.length; j++) {            $('#' + dg).datagrid('mergeCells', {                index: merges[j].index,                field: cellname,                rowspan: merges[j].rowspan            });        }    }}

 

转载于:https://www.cnblogs.com/Ajoying/p/EasyUi_datagrid.html

你可能感兴趣的文章
js 判断滚动条的滚动方向
查看>>
关于springboot启动时候报错:springboot Failed to parse configuration class [Application]
查看>>
java中Class的使用详解
查看>>
css,js文件后面加一个版本号
查看>>
webpack第一节(2)
查看>>
python之asyncio三种应用方法
查看>>
Laravel 的文件存储 - Storage
查看>>
转:[Server] 在 Windows 上安裝 PHP 5.3 開發環境
查看>>
【IE6的疯狂之二】IE6中PNG Alpha透明(全集)
查看>>
第一个Shell脚本
查看>>
C++ 小笔记
查看>>
Mysql 语句优化
查看>>
例子:进度条
查看>>
包含单引号的sql
查看>>
HTML 基础 2
查看>>
Java 最常见 200+ 面试题全解析:面试必备(转载)
查看>>
LinkedList
查看>>
Spring框架下PropertyPlaceholderConfigurer类配置roperties文件
查看>>
SQL查询优化
查看>>
使用子查询
查看>>