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 ;
}
}
}
EasyUi合并单元表格
最新推荐文章于 2023-12-01 08:36:26 发布