1、行合并想要的样式如下,需要合并4列的行,如下图(数据为模拟数据,如有雷同,纯属人品爆发)
##controller代码:
// 计算计划类型的合并的planRowSpan
int tiefaRowSpan = Integer.parseInt(String.valueOf(statisticsTieFaConList.size()));
int tiedaoRowSpan = Integer.parseInt(String.valueOf(statisticsTieDaoConList.size()));
// 客户所在位置下标
int logFlag = 0;
// 客户名称1,是判断标准
String logName1 = "";
// 客户名称2,随着循环变化
String logName2 = "";
// 客户的合并的行数
int logRowSpan = 1;
// 供应商所在位置下标
int supFlag = 0;
// 供应商名称1,是判断标准
String supName1 = "";
// 供应商名称2,随着循环变化
String supName2 = "";
// 供应商的合并的行数
int supRowSpan = 1;
// 货票号所在位置下标
int cargoFlag = 0;
// 货票号1,是判断标准
String cargoName1 = "";
// 货票号2,随着循环变化
String cargoName2 = "";
// 货票号的合并的行数
int cargoRowSpan = 1;
// 计算行的合并的rowspan的值 1、planRowSpan:计划类型,2、logRowSpan:客户公司,3、supRowSpan:运输公司,4、cargoRowSpan:货票号
for (int i=0; i < resultList.size(); i++) {
// 因为铁发和铁到是按照类别分开的,所以按照铁发的数量进行判断的分割
if (i == 0) {
resultList.get(i).put("planRowSpan", tiefaRowSpan);
logFlag = i;
logName1 = String.valueOf(resultList.get(i).get("logCompany"));
supFlag = i;
supName1 = String.valueOf(resultList.get(i).get("supCompany"));
cargoFlag = i;
cargoName1 = String.valueOf(resultList.get(i).get("cargobillCode"));
} else if (i < tiefaRowSpan){
resultList.get(i).put("planRowSpan", 0);
} else if (i == tiefaRowSpan) {
resultList.get(i).put("planRowSpan", tiedaoRowSpan);
resultList.get(supFlag).put("supRowSpan", supRowSpan);
resultList.get(cargoFlag).put("cargoRowSpan", cargoRowSpan);
supFlag = i;
supName1 = String.valueOf(resultList.get(i).get("supCompany"));
cargoFlag = i;
cargoName1 = String.valueOf(resultList.get(i).get("cargobillCode"));
} else if (i > tiefaRowSpan) {
resultList.get(i).put("planRowSpan", 0);
}
// 取物流商的名称进行对比
if (i != 0 && i != tiefaRowSpan) {
logName2 = String.valueOf(resultList.get(i).get("logCompany"));
supName2 = String.valueOf(resultList.get(i).get("supCompany"));
cargoName2 = String.valueOf(resultList.get(i).get("cargobillCode"));
if (logName1.equals(logName2)) {
logRowSpan = logRowSpan + 1;
resultList.get(i).put("logRowSpan", 0);
if (supName1.equals(supName2)) {
supRowSpan = supRowSpan + 1;
resultList.get(i).put("supRowSpan", 0);
if (cargoName1.equals(cargoName2)) {
cargoRowSpan = cargoRowSpan + 1;
resultList.get(i).put("cargoRowSpan", 0);
} else {
resultList.get(cargoFlag).put("cargoRowSpan", cargoRowSpan);
cargoFlag = i;
cargoRowSpan = 1;
cargoName1 = String.valueOf(resultList.get(i).get("cargobillCode"));
cargoName2 = "";
}
} else {
resultList.get(supFlag).put("supRowSpan", supRowSpan);
supFlag = i;
supRowSpan = 1;
supName1 = String.valueOf(resultList.get(i).get("supCompany"));
supName2 = "";
resultList.get(cargoFlag).put("cargoRowSpan", cargoRowSpan);
cargoFlag = i;
cargoRowSpan = 1;
cargoName1 = String.valueOf(resultList.get(i).get("cargobillCode"));
cargoName2 = "";
}
} else {
resultList.get(logFlag).put("logRowSpan", logRowSpan);
logFlag = i;
logRowSpan = 1;
logName1 = String.valueOf(resultList.get(i).get("logCompany"));
logName2 = "";
resultList.get(supFlag).put("supRowSpan", supRowSpan);
supFlag = i;
supRowSpan = 1;
supName1 = String.valueOf(resultList.get(i).get("supCompany"));
supName2 = "";
resultList.get(cargoFlag).put("cargoRowSpan", cargoRowSpan);
cargoFlag = i;
cargoRowSpan = 1;
cargoName1 = String.valueOf(resultList.get(i).get("cargobillCode"));
cargoName2 = "";
}
} else if (i == tiefaRowSpan) {
resultList.get(logFlag).put("logRowSpan", logRowSpan);
logFlag = i;
logRowSpan = 1;
logName1 = String.valueOf(resultList.get(i).get("logCompany"));
logName2 = "";
resultList.get(supFlag).put("supRowSpan", supRowSpan);
supFlag = i;
supRowSpan = 1;
supName1 = String.valueOf(resultList.get(i).get("supCompany"));
supName2 = "";
resultList.get(cargoFlag).put("cargoRowSpan", cargoRowSpan);
cargoFlag = i;
cargoRowSpan = 1;
cargoName1 = String.valueOf(resultList.get(i).get("cargobillCode"));
cargoName2 = "";
}
}
resultList.get(logFlag).put("logRowSpan", logRowSpan);
resultList.get(supFlag).put("supRowSpan", supRowSpan);
resultList.get(cargoFlag).put("cargoRowSpan", cargoRowSpan);
##js代码:
"ordering" : false,
// 按照最新下发的订单,订单编码是升序的排列顺序
// order: [[ 5, "desc" ]],
columnDefs: [{
targets: [0,1,2,3], //第1,2,3列
createdCell: function (td, cellData, rowData, row, col) {
var rowspan = 1;
if(col == 0){
rowspan = rowData.planRowSpan;
}
if(col == 1){
rowspan = rowData.logRowSpan;
}
if(col == 2){
rowspan = rowData.supRowSpan;
}
if(col == 3){
rowspan = rowData.cargoRowSpan;
}
if (rowspan > 1) {
$(td).attr('rowspan', rowspan)
}
if (rowspan == 0) {
$(td).remove();
}
}
}],