table.render({elem: '#samples',url: '/index/Develorderss/samplelists?od_id='+od_id //数据接口,page: { //支持传入 laypage 组件的所有参数(某些参数除外,如:jump/elem) - 详见文档layout: ['prev', 'page', 'next', 'count','skip','limit'] //自定义分页布局//,curr: 5 //设定初始在第 5 页,groups:10 //只显示 1 个连续页码,first: false //不显示首页,last: false //不显示尾页},limit:10,cols: [[ //表头// ,给供应商做信笺时间,供应商回信的时间,寄客户信笺时间,确认的时间,是否确认(如果是色样就填颜色的结果),创建日期{checkbox: true, fixed: true},{field:'name',title:'类型',width:'10%'},{field:'sm_name',title:'材料',width:'10%'},{field:'color_name',title:'颜色',width:'10%'},{field:'sample_delivery',title:'交期',width:'150'},{field:'sample_delivery',title:'寄出供应商信笺',width:'150'},{field:'sample_delivery',title:'收到供应商信笺',width:'150'},{field:'sample_delivery',title:'寄出客户信笺',width:'150'},{field:'sample_delivery',title:'收到客户信笺',width:'150'},{field:'sample_delivery',title:'确认时间',width:'150'},{field:'is_confirm',title:'是否确认',width:'10%',templet:function(d){if(d.is_confirm==0){return "<div style='color:red'>不确认</div>";}else if(d.is_confirm==1){return "<div style='color:green'>确认</div>";}else{return "";}}},{field:'create_date',title:'创建日期',width:'150'},{title:'操作',width:'320',fixed:'right',templet:function(d){var str = '';str += "<div class='layui-btn' lay-event='detail'>详情</div>"; str += "<div class='layui-btn' lay-event='edit'>编辑</div>"; str += "<div class='layui-btn' lay-event='del'>删除</div>"; str += "<div class='layui-btn' lay-event='suggest'>意见资料</div>";return str; }}]],jump:function(obj, first){if(!first){$.get('/index/Develorderss/samplelists?od_id='+od_id,{page:obj.curr},function(data){console.log(data);});}},done:function(res, curr, count) {merge(res);//调用}});
function merge(res) {var data = res.data;var mergeIndex = 0;//定位需要添加合并属性的行数var mark = 1; //这里涉及到简单的运算,mark是计算每次需要合并的格子数var columsName = ['name','sm_name'];//需要合并的列名称var columsIndex = [1,2];//需要合并的列索引值for (var k = 0; k < columsName.length; k++) { //这里循环所有要合并的列var trArr = $(".layui-table-body>.layui-table").find("tr");//所有行for (var i = 1; i < res.data.length; i++) { //这里循环表格当前的数据var tdCurArr = trArr.eq(i).find("td").eq(columsIndex[k]);//获取当前行的当前列var tdPreArr = trArr.eq(mergeIndex).find("td").eq(columsIndex[k]);//获取相同列的第一列if (data[i][columsName[k]] === data[i-1][columsName[k]]) { //后一行的值与前一行的值做比较,相同就需要合并mark += 1;tdPreArr.each(function () {//相同列的第一列增加rowspan属性$(this).attr("rowspan", mark);});tdCurArr.each(function () {//当前行隐藏$(this).css("display", "none");});}else {mergeIndex = i;mark = 1;//一旦前后两行的值不一样了,那么需要合并的格子数mark就需要重新计算}}mergeIndex = 0;mark = 1;}
}