/* eslint max-len: 0 */
/* eslint no-console: 0 */
import React from 'react';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';


const products = [];

function addProducts(quantity) {
  const startId = products.length;
  let price = 2100;
  for (let i = 0; i < quantity; i++) {
    const id = startId + i;

    if (id % 5 === 0) {
      price += 100;
    }

    products.push({
      id: id,
      name: 'Item name ' + (id % 8 + 1),
      price: price
    });
  }
}

addProducts(15);

export default class ExternalMultiSort extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      sortName: [],
      sortOrder: []
    };
    this.onSortChange = this.onSortChange.bind(this);
  }

  onSortChange(name, order) {
    const sortName = [];
    const sortOrder = [];

    for (let i = 0; i < this.state.sortName.length; i++) {
      if (this.state.sortName[i] !== name) {
        sortName.push(this.state.sortName[i]);
        sortOrder.push(this.state.sortOrder[i]);
      }
    }

    sortName.push(name);
    sortOrder.push(order);
    this.setState({
      sortName,
      sortOrder
    });
  }

  render() {
    const options = {
      // reassign the multi sort list by an Array
      // if you dont want to control al the sort list, you can only assign the String to sortName and sort Order
      sortName: this.state.sortName,
      sortOrder: this.state.sortOrder,
      onSortChange: this.onSortChange
    };
    return (
      <div>
        <p style={ { color: 'red' } }>sort: sortName={ this.state.sortName }, sortOrder={ this.state.sortOrder }</p>
        <BootstrapTable data={ products } options={ options } multiColumnSort={ 2 }>
          <TableHeaderColumn dataField='id' isKey={ true } dataSort={ true }>Product ID</TableHeaderColumn>
          <TableHeaderColumn dataField='name' dataSort={ true }>Product Name</TableHeaderColumn>
          <TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
        </BootstrapTable>
      </div>
    );
  }
}

@@ -731,20 +731,68 @@
 (this);%0A
+    this.cleanSort = this.cleanSort.bind(this);%0A
   %7D%0A
-
 %0A  onSor
@@ -1198,16 +1198,105 @@
 );%0A  %7D%0A%0A
+  cleanSort() %7B%0A    this.setState(%7B%0A      sortName: %5B%5D,%0A      sortOrder: %5B%5D%0A    %7D);%0A  %7D%0A%0A
   render
@@ -1619,16 +1619,16 @@
 eturn (%0A
-
       %3Cd
@@ -1627,24 +1627,110 @@
       %3Cdiv%3E%0A
+        %3Cbutton className='btn ben-default' onClick=%7B this.cleanSort %7D%3EClean%3C/button%3E%0A
         %3Cp s

add clean multi sort functionality