4

I have a Bootstrap-Table with a a button to add a new row of data. I would like to color the cell of a certain column (text2) for each new row as it's inserted. I am using the built in method cellStyle() as shown here: http://jsfiddle.net/wenyi/e3nk137y/9/, but the function method never seems to be called.

Documentation for Bootstrap-Table: http://bootstrap-table.wenzhixin.net.cn/documentation/

Table declaration with cellStyle parameter:

<table id="table" data-pagination="true"  data-cell-style="cellStyle" class="table table-striped"></table>

function to add style:

function cellStyle(value, row, index, field) {
  if (index === 0 && field == 'text2') {
    return {classes: 'warning'};
  }
  else {
    return {};
  }
}

My full code:

http://jsfiddle.net/wtg54xpy/

user2242044
  • 8,803
  • 25
  • 97
  • 164

1 Answers1

4

Something similar to this? http://jsfiddle.net/fp61qL0k/

The documentation says you should be adding the function to the table column header, not the table itself. From here it's just manipulating the function.

{
   field: 'text2',
   title: 'TEXT 2',
   cellStyle: cellStyle,
}
MD Ashik
  • 9,117
  • 10
  • 52
  • 59
davidatthepark
  • 1,235
  • 1
  • 13
  • 25