条带引导表:如何仅为1列更改条纹背景颜色?

时间:2018-03-06 14:52:18

标签: angularjs-ng-repeat angular-ui-bootstrap ngtable


我对Bootstrap table striped: How do I change the stripe background colour?提出了类似的问题。但主要区别在于我想仅为一列改变颜色的交替。
这是我的ng-table的特征,我想用标题' Srv'来改变第一列的背景颜色。

<table ng-table="fondiTable_C" class="table table-condensed table-bordered table-striped" template-pagination="app/components/gestioneFondi/pagerTemplate.html">
                <tr ng-repeat="fondo in data_C">    
                    <td class="i9fontPre text-center" data-title="'Srv'" header-class="'i9header'">{{::fondo.area}}</td>
                    <td class="i9fontPre text-left" data-title="'Chiave IB'" header-class="'i9header'">{{::fondo | formatChiave}}</td>  
                    <td class="i9font text-center" data-title="'Stato Pratica'" header-class="'i9header'">{{::fondo.stato}}</td>
                    <td class="i9font text-center" data-title="'Flag S/V'" header-class="'i9header'">{{::fondo.fvs}}</td>
                    <td class="i9font text-right" data-title="'Fondo bucket&nbsp;1 (EUR)'" header-class="'i9header'">{{::fondo.fnd1 | number:2}}</td>
                    <td class="i9font text-right" data-title="'Fondo bucket&nbsp;2 (EUR)'" header-class="'i9header'">{{::fondo.fnd2 | number:2}}</td>
                    <td class="i9font text-center" data-title="'Bucket'" header-class="'i9header'">{{::fondo.bktDH}}</td>
                    <td class="i9font text-right" data-title="'Fondo IFRS9 (EUR)'" header-class="'i9header'">{{::fondo.fndDH | number:2}}</td>
                    <td class="i9font text-center" data-title="'Rapporto'" header-class="'i9header'">{{::fondo | formatRapporto}}</td>
                    <td class="i9font text-center" data-title="'Cdg'" header-class="'i9header'">{{::fondo.cdg | formatCdg}}</td>
                    <td class="i9font text-center" data-title="'FT'" header-class="'i9header'">{{::fondo.fTec}}</td>
                </tr>
            </table>
你可以帮帮我吗? 提前谢谢

1 个答案:

答案 0 :(得分:1)

您可以使用ngClass有条件地将样式应用于特定单元格,ngRepeat会为每一行重新绘制样式。

像这样的东西

<tr ng-repeat="unit in data">
  <td ng-class="{'highlight': selected==='name'}">{{unit.name}}</td>
  <td ng-class="{'highlight': selected==='model'}">{{unit.model}}</td>
  <td ng-class="{'highlight': selected==='price'}">{{unit.price}}</td>
</tr>

取决于selected的值,td类将应用highlight

Here's a demo