<script>
  init({
    title: 'Issue #563',
    desc: 'Change the background color on selected rows (<a href="https://github.com/wenzhixin/bootstrap-table/issues/563" target="_blank">#563</a>).',
    links: ['bootstrap-table.min.css'],
    scripts: ['bootstrap-table.min.js']
  })
</script>

<style>
.active {
  color: red;
  font-weight: bold;
}
</style>

<table
  id="table"
  data-toggle="table"
  data-url="json/data1.json"
  data-show-refresh="true"
  data-pagination="true"
  data-row-style="rowStyle">
  <thead>
  <tr>
    <th data-field="name">Item Name</th>
    <th data-field="price">Item Price</th>
  </tr>
  </thead>
</table>

<script>
  var $table = $('#table')
  var selectedRow = {}

  function mounted() {
    $table.on('click-row.bs.table', function (e, row, $element) {
      selectedRow = row
      $('.active').removeClass('active')
      $($element).addClass('active')
    })
  }

  function rowStyle(row) {
    if (row.id === selectedRow.id) {
      return {
        classes: 'active'
      }
    }
    return {}
  }
</script>
