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/

1 Answer 1

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,
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I did see the table header thing. The tricky part is I need it just on the new rows, not the whole column.
There are a few ways you can do that. Check this out jsfiddle.net/85h32nyz

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.