angular-ui-grid merge cells in column(合并列上的单元格)


问题:

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.

rowspan



摘自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行有文字显示。








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值