问题:
I would like to pull a feature request that you implement a rowspan over 2 or more rows.
This feature greatly help me improving my cell templates when I have a double lessons to prepare!
It should be possible to decide during runtime wether to render a row with a single cell or a merge cell/cells depending on a viewmodels property.
摘自angular-ui-grid的issue845
包括issue1464 和 issue259 都有提出这个问题
插件作者在issue1464中提到的解决方案是Custom template(自定义模板)
This is now included in the templates tutorial: http://ui-grid.info/docs/#/tutorial/317_custom_templates.
Merging all cells in a row is reasonably straightforward, merging just some cells would be somewhat more complex, but still possible through that same mechanism.
在issue1464中热心网友给出的实例是:
http://plnkr.co/edit/Ze6axa9GljdTpEcfYkIb?p=preview
================
更新:
以上方法都不能很好的解决问题,本人探索出的一个方法是:
第一步:利用ui grid的gridOptions.columnDefs提供的cellClass()方法,通过修改css来控制单元格的border-bottom显示。
第二步:利用ui grid的gridOptions.columnDefs提供的cellTemplate()方法,设置自定义的cellTemplate,让位置上相对垂直居中的某一行的单元格的文字显示,其它单元格的文字为空字符串,不显示
例子:
.sj_cszbCell{border-bottom:1px solid #d4d4d4 !important; background-color: white !important; text-align:center;}
.sjCell{background-color: white !important; text-align:center;}
.sj_cszbCell会有1px的border-bottom。
function setSjCellClass(row,col){
if(row.entity["zb"]=="超时占比") //判断条件是该行是合并列的最后一行
return 'sj_cszbCell'; //则有底部边框
else
return 'sjCell';
}
var sjcellTemplate = '<div style="font-size:14px;position:relative;top:14px;">{{row.entity.zb=="流程完成率"?row.entity.sj:""}}</div>';
var columnDefs = [
{name:"时间", field:"sj",cellTemplate:sjcellTemplate, enableHiding:false,
cellClass:function(grid, row, col){ return setSjCellClass(row,col);}
}]
$scope.gridOptions.columnDefs = columnDefs;
在时间的文字显示上,{{row.entity.zb=="流程完成率"?row.entity.sj:""}}
让第二行有文字显示,其它行为空字符串,无文字显示。
从而更加逼近合并列的效果。
为什么让第二行显示文字呢?
因为合并4行时,第二行在位置上相对垂直居中。同理,如果是合并5行,则应该只让第3行有文字显示。