ng2-table how to add style to specific row

4.7k views Asked by At

Hi I'm new with angular 2. I'm using ng2-table. I added to my website table like this. I need to add a color to specific row inside the table. How is that possible ? I tried to add it like the tutorial did with his columns but without success.

2

There are 2 answers

0
GroundIns On BEST ANSWER

Found an answer, taken from here: https://github.com/valor-software/ng2-table/issues/342

We can change te color of the row by adding some style to it like this:

A quick and dirty solution:

Step 1: Integrate jQuery

Step 2: Give your result table an ID like:

<ng-table id="resultDataTable" ...

Step 3: Modify your onCellClick method:

onCellClick(data: any): any {
/* get index of row */
let index = this.tableData.indexOf(data.row);  

/* add an class 'active' on click */
$('#resultDataTable').on('click', 'tr', function (event: any) {
  //noinspection TypeScriptUnresolvedFunction
  $(this).addClass('active').siblings().removeClass('active');
});}
5
Faouzi Oudouh On

Check their style file provided to know what css-class Names are using and try to override them:

E.g. of classes used: table dataTable table-striped table-bordered

CSS:

table.dataTable tbody th, table.dataTable tbody td {
  padding: 8px 10px;
  background-color: red;
}

Reulsts: enter image description here