EasyUi合并单元表格

function tableInit(){
							var tabs_height = $("#content_tab").height() == null ? $(document).height() : $("#content_tab").height();
				            $("#table-div").datagrid({
				                height : tabs_height - 65,
				                singleSelect : true,
				                url : _basePath + 'cloud/all/queryList',
				                method : 'post',
				                loadMsg : '加载中',
				                pagination : false,
				                rownumbers : true,
				                fitColumns:false,
				                title:"云机器使用情况汇总",
				                toolbar:[{
				                    text : "刷新",
				                    iconCls : "icon-reload",
				                    handler : function() {
				                        $("#table-div").datagrid("reload");
				                    }
				                }],
				                columns : [ [
				                    {field : 'id',title : 'ID',width : 100,align : 'center',hidden: 'true'},
				                    {field : 'cloudId',title : 'cloudId',width : 100,align : 'center',hidden: 'true'},
				                    {field : 'cloudName',title : '云厂商',width : 150,align : 'center'},
				                    {field : 'mainName',title : '大类',width : 150,align : 'center'},
				                    {field : 'num',title : '数量',width : 150,align : 'center'},
				                    {field : 'detial', title : '详情',width : 150,align : 'center',
				                    	formatter: function(value,row,index){
				                               
				                    		return "<a href='#' οnclick='showDetail("+ row.cloudId+ ")'>查看</a>";
				                        }
				                    }
				                ]],
				                onLoadSuccess : function(data) {
				                    if (data.total == 0) {
				                        //添加一个新数据行,第一列的值为你需要的提示信息,然后将其他列合并到第一列来,注意修改colspan参数为你columns配置的总列数
				                        $(this).datagrid('appendRow', {
				                            'cloudId' : '<div style="text-align:center;color:red">没有数据!</div>'
				                        }).datagrid('mergeCells',
				                            {
				                                index : 0,
				                                field : 'cloudId',
				                                colspan : 4
				                            });
				                    }else{
				                    	mymergeCellsByField();
				                    }
				                }
				            });
						}





function mymergeCellsByField() {
							var rows = $("#table-div").datagrid('getRows');
							var beforeText = '';//当前的文本
							var nowText = '';//现在的文本
							var count = 1;//需要合并的行数
							var rowInd = 0;//合并的行位置
							for (var i = 0; i <= rows.length; i++) {
								if (i == rows.length) {
									nowText = "";
								} else {
									nowText = rows[i].cloudName;//判断链接字符串怎么样的才需要合并(+row[i].*)
								}
								if (beforeText == nowText) {
									count += 1;
								} else {
									//合并前几行
									$("#table-div").datagrid('mergeCells', {
										index : rowInd,
										field : 'cloudName',
										rowspan : count,
										colspan : null
									});
									count = 1
									rowInd = i
								}
								if (i != rows.length) {
									beforeText = rows[i].cloudName ;
								}
							}
						}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值