Skip to content

Commit

Permalink
Merge pull request #1 from khinlatt/feautre/multi_column_search
Browse files Browse the repository at this point in the history
Feature (Multiple column search) - feature/multiple column search
  • Loading branch information
khinlatt committed Nov 3, 2015
2 parents 936fbdc + 597c69e commit 4874169
Show file tree
Hide file tree
Showing 6 changed files with 18,077 additions and 19,388 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ You can reference [here](http://allenfang.github.io/react-bootstrap-table/docs.h
| insertRow | Bool | Set true to enable row insertion on table. |
| deleteRow | Bool | Set true to enable row deletion on table. |
| search | Bool | Set true to enable search function on table. |
| multiColumnSearch | Bool | Set true to enable words search on multiple column function on table from a search box. |
| searchPlaceholder | String | The place holder on search text fields |
| keyField | String | Same as ```isKey``` in <TableHeaderColumn> |
| trClassName | String or Function | Assign the row(tr) class, accept string or function, if use function, will pass ```rowData``` and ```rowIndex``` params and should return string presented class. for examples:</br>**function trClassFormat(rowData,rowIndex){**</br>&nbsp;&nbsp;&nbsp;**return rowIndex%2==0?"tr-odd":"tr-even";**</br>**}** |
Expand Down
37,411 changes: 18,037 additions & 19,374 deletions dist/react-bootstrap-table.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions lib/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object.defineProperty(exports, '__esModule', {

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

Expand Down Expand Up @@ -454,7 +454,7 @@ var BootstrapTable = (function (_React$Component) {
}, {
key: 'handleSearch',
value: function handleSearch(searchText) {
this.store.search(searchText);
this.store.search(searchText, this.props.multiColumnSearch);
var result = undefined;
if (this.props.pagination) {
var sizePerPage = this.refs.pagination.getSizePerPage();
Expand Down Expand Up @@ -566,7 +566,7 @@ var BootstrapTable = (function (_React$Component) {
BootstrapTable.propTypes = {
keyField: _react2['default'].PropTypes.string,
height: _react2['default'].PropTypes.string,
data: _react2['default'].PropTypes.array,
data: _react2['default'].PropTypes.oneOfType([_react2['default'].PropTypes.array, _react2['default'].PropTypes.object]),
remote: _react2['default'].PropTypes.bool, // remote data, default is false
striped: _react2['default'].PropTypes.bool,
bordered: _react2['default'].PropTypes.bool,
Expand Down Expand Up @@ -637,6 +637,7 @@ BootstrapTable.defaultProps = {
insertRow: false,
deleteRow: false,
search: false,
multiColumnSearch: false,
columnFilter: false,
trClassName: '',
options: {
Expand Down
22 changes: 17 additions & 5 deletions lib/store/TableDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Object.defineProperty(exports, '__esModule', {

var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

Expand Down Expand Up @@ -221,19 +221,31 @@ var TableDataStore = (function () {
}
}, {
key: 'search',
value: function search(searchText) {
value: function search(searchText, multiColumnSearch) {
if (searchText.trim() === "") {
this.filteredData = null;
this.isOnFilter = false;
this.searchText = null;
} else {
this.searchText = searchText;
var searchTextArray = [];
this.filteredData = this.data.filter(function (row) {
var valid = false;

if (multiColumnSearch) {
searchTextArray = searchText.split(' ');
} else {
searchTextArray.push(searchText);
}

for (var key in row) {
if (row[key] && row[key].toString().toLowerCase().indexOf(searchText.toLowerCase()) !== -1) {
valid = true;
break;
if (row[key]) {
searchTextArray.forEach(function (text) {
if (row[key].toString().toLowerCase().indexOf(text.toLowerCase()) !== -1) {
valid = true;
}
});
if (valid) break;
}
}
return valid;
Expand Down
3 changes: 2 additions & 1 deletion src/BootstrapTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class BootstrapTable extends React.Component {
}

handleSearch(searchText) {
this.store.search(searchText);
this.store.search(searchText, this.props.multiColumnSearch);
let result;
if (this.props.pagination) {
let sizePerPage = this.refs.pagination.getSizePerPage();
Expand Down Expand Up @@ -562,6 +562,7 @@ BootstrapTable.defaultProps = {
insertRow: false,
deleteRow: false,
search: false,
multiColumnSearch: false,
columnFilter: false,
trClassName: '',
options: {
Expand Down
21 changes: 16 additions & 5 deletions src/store/TableDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,31 @@ export class TableDataStore {
}
}

search(searchText) {
search(searchText, multiColumnSearch) {
if (searchText.trim() === "") {
this.filteredData = null;
this.isOnFilter = false;
this.searchText = null;
} else {
this.searchText = searchText;
var searchTextArray = [];
this.filteredData = this.data.filter(function (row) {
let valid = false;

if (multiColumnSearch) {
searchTextArray = searchText.split(' ');
} else {
searchTextArray.push(searchText);
}

for (var key in row) {
if (row[key] &&
row[key].toString().toLowerCase().indexOf(searchText.toLowerCase()) !== -1) {
valid = true;
break;
if (row[key]) {
searchTextArray.forEach(function(text) {
if (row[key].toString().toLowerCase().indexOf(text.toLowerCase()) !== -1) {
valid = true;
}
});
if (valid) break;
}
}
return valid;
Expand Down

0 comments on commit 4874169

Please sign in to comment.