From 1f0464948b786e60a46b17ff2c10442cead22724 Mon Sep 17 00:00:00 2001 From: Jared Chavez Date: Thu, 13 Oct 2016 14:45:07 -0700 Subject: [PATCH 1/6] persist filter across table refreshes --- build/reactable.js | 14 +++++++++++++- lib/reactable/table.js | 14 +++++++++++++- src/reactable/table.jsx | 16 +++++++++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/build/reactable.js b/build/reactable.js index 92b762b5..55c62ab0 100644 --- a/build/reactable.js +++ b/build/reactable.js @@ -1257,6 +1257,11 @@ window.ReactDOM["default"] = window.ReactDOM; }; } }, { + key: 'getCurrentFilter', + value: function getCurrentFilter(propFilter) { + return this.state.filter !== undefined && propFilter === '' ? this.state.filter : propFilter; + } + }, { key: 'updateCurrentSort', value: function updateCurrentSort(sortBy) { if (sortBy !== false && sortBy.column !== this.state.currentSort.column && sortBy.direction !== this.state.currentSort.direction) { @@ -1279,13 +1284,20 @@ window.ReactDOM["default"] = window.ReactDOM; this.filterBy(this.props.filterBy); } }, { + key: 'getCurrentFilter', + value: function getCurrentFilter(propFilter) { + return this.state.filter !== undefined && propFilter === '' ? this.state.filter : propFilter; + } + }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { this.initialize(nextProps); this.updateCurrentPage(nextProps.currentPage); this.updateCurrentSort(nextProps.sortBy); this.sortByCurrentSort(); - this.filterBy(nextProps.filterBy); + + var filter = this.getCurrentFilter(nextProps.filterBy); + this.filterBy(filter); } }, { key: 'applyFilter', diff --git a/lib/reactable/table.js b/lib/reactable/table.js index e2235b66..0cc430da 100644 --- a/lib/reactable/table.js +++ b/lib/reactable/table.js @@ -271,6 +271,11 @@ var Table = (function (_React$Component) { }; } }, { + key: 'getCurrentFilter', + value: function getCurrentFilter(propFilter) { + return this.state.filter !== undefined && propFilter === '' ? this.state.filter : propFilter; + } + }, { key: 'updateCurrentSort', value: function updateCurrentSort(sortBy) { if (sortBy !== false && sortBy.column !== this.state.currentSort.column && sortBy.direction !== this.state.currentSort.direction) { @@ -293,13 +298,20 @@ var Table = (function (_React$Component) { this.filterBy(this.props.filterBy); } }, { + key: 'getCurrentFilter', + value: function getCurrentFilter(propFilter) { + return this.state.filter !== undefined && propFilter === '' ? this.state.filter : propFilter; + } + }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(nextProps) { this.initialize(nextProps); this.updateCurrentPage(nextProps.currentPage); this.updateCurrentSort(nextProps.sortBy); this.sortByCurrentSort(); - this.filterBy(nextProps.filterBy); + + var filter = this.getCurrentFilter(nextProps.filterBy); + this.filterBy(filter); } }, { key: 'applyFilter', diff --git a/src/reactable/table.jsx b/src/reactable/table.jsx index 82601180..ef401639 100644 --- a/src/reactable/table.jsx +++ b/src/reactable/table.jsx @@ -230,6 +230,12 @@ export class Table extends React.Component { }; } + getCurrentFilter(propFilter) { + return (this.state.filter !== undefined && propFilter === '') ? + this.state.filter : + propFilter; + } + updateCurrentSort(sortBy) { if (sortBy !== false && sortBy.column !== this.state.currentSort.column && @@ -251,12 +257,20 @@ export class Table extends React.Component { this.filterBy(this.props.filterBy); } + getCurrentFilter(propFilter) { + return (this.state.filter !== undefined && propFilter === '') ? + this.state.filter : + propFilter; + } + componentWillReceiveProps(nextProps) { this.initialize(nextProps); this.updateCurrentPage(nextProps.currentPage) this.updateCurrentSort(nextProps.sortBy); this.sortByCurrentSort(); - this.filterBy(nextProps.filterBy); + + let filter = this.getCurrentFilter(nextProps.filterBy); + this.filterBy(filter); } applyFilter(filter, children) { From cd8c1df37c68b689ddb00894ae575a657cecfbc9 Mon Sep 17 00:00:00 2001 From: Aaron Ryden Date: Tue, 13 Dec 2016 17:39:10 -0500 Subject: [PATCH 2/6] sortable on other fields --- build/reactable.js | 4 ++-- lib/reactable/table.js | 4 ++-- src/reactable/table.jsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/reactable.js b/build/reactable.js index 7671bed2..1990cc01 100644 --- a/build/reactable.js +++ b/build/reactable.js @@ -1358,9 +1358,9 @@ window.ReactDOM["default"] = window.ReactDOM; } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }).bind(this)); diff --git a/lib/reactable/table.js b/lib/reactable/table.js index e2235b66..fff06a42 100644 --- a/lib/reactable/table.js +++ b/lib/reactable/table.js @@ -365,9 +365,9 @@ var Table = (function (_React$Component) { } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }).bind(this)); diff --git a/src/reactable/table.jsx b/src/reactable/table.jsx index 82601180..0faaf8a4 100644 --- a/src/reactable/table.jsx +++ b/src/reactable/table.jsx @@ -323,9 +323,9 @@ export class Table extends React.Component { } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }.bind(this)); From d962b84866d0fabd37bd38ec5eb51d7011688596 Mon Sep 17 00:00:00 2001 From: Eric Fennell Date: Thu, 13 Oct 2016 15:05:24 -0500 Subject: [PATCH 3/6] Pass column props pulled from header to s. --- build/reactable.js | 10 ++++++++-- lib/reactable/tr.js | 10 ++++++++-- src/reactable/tr.jsx | 3 +-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/build/reactable.js b/build/reactable.js index 55c62ab0..997bef6c 100644 --- a/build/reactable.js +++ b/build/reactable.js @@ -513,6 +513,8 @@ window.ReactDOM["default"] = window.ReactDOM; 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 _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } @@ -536,10 +538,14 @@ window.ReactDOM["default"] = window.ReactDOM; console.log(children); } - children = children.concat(this.props.columns.map((function (column, i) { + children = children.concat(this.props.columns.map((function (_ref, i) { + var _ref$props = _ref.props; + var props = _ref$props === undefined ? {} : _ref$props; + + var column = _objectWithoutProperties(_ref, ['props']); + if (this.props.data.hasOwnProperty(column.key)) { var value = this.props.data[column.key]; - var props = {}; if (typeof value !== 'undefined' && value !== null && value.__reactableMeta === true) { props = value.props; diff --git a/lib/reactable/tr.js b/lib/reactable/tr.js index c91e872c..03331792 100644 --- a/lib/reactable/tr.js +++ b/lib/reactable/tr.js @@ -12,6 +12,8 @@ var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_ag function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } +function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } @@ -45,10 +47,14 @@ var Tr = (function (_React$Component) { console.log(children); } - children = children.concat(this.props.columns.map((function (column, i) { + children = children.concat(this.props.columns.map((function (_ref, i) { + var _ref$props = _ref.props; + var props = _ref$props === undefined ? {} : _ref$props; + + var column = _objectWithoutProperties(_ref, ['props']); + if (this.props.data.hasOwnProperty(column.key)) { var value = this.props.data[column.key]; - var props = {}; if (typeof value !== 'undefined' && value !== null && value.__reactableMeta === true) { props = value.props; diff --git a/src/reactable/tr.jsx b/src/reactable/tr.jsx index 5374f96a..003da33c 100644 --- a/src/reactable/tr.jsx +++ b/src/reactable/tr.jsx @@ -14,10 +14,9 @@ export class Tr extends React.Component { ) { if (typeof(children.concat) === 'undefined') { console.log(children); } - children = children.concat(this.props.columns.map(function(column, i) { + children = children.concat(this.props.columns.map(function({ props = {}, ...column}, i) { if (this.props.data.hasOwnProperty(column.key)) { var value = this.props.data[column.key]; - var props = {}; if ( typeof(value) !== 'undefined' && From 62962d1b600b60041b512426b5a0b292ca736d0b Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Fri, 18 Nov 2016 16:11:03 -0500 Subject: [PATCH 4/6] Version 0.14.1 * fix more unknown prop warnings --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index f96b0166..c0577ca4 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "reactable", - "version": "0.14.0", + "version": "0.14.1", "main": "build/reactable.js", "dependencies": { "react": "0.14" diff --git a/package.json b/package.json index 91677bc2..926b243b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reactable", - "version": "0.14.0", + "version": "0.14.1", "description": "Fast, flexible, simple data tables in React", "main": "./lib/reactable.js", "repository": { From 328219e6417246e4569c35660ae19f5ec186890f Mon Sep 17 00:00:00 2001 From: Jason Blanchard Date: Tue, 15 Nov 2016 18:03:53 -0500 Subject: [PATCH 5/6] checking if !th in thead.jsx --- build/reactable.js | 1 + lib/reactable/thead.js | 1 + src/reactable/thead.jsx | 1 + tests/reactable_test.jsx | 20 ++++++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/build/reactable.js b/build/reactable.js index 997bef6c..9e003aa6 100644 --- a/build/reactable.js +++ b/build/reactable.js @@ -758,6 +758,7 @@ window.ReactDOM["default"] = window.ReactDOM; var columns = []; _react['default'].Children.forEach(component.props.children, function (th) { var column = {}; + if (!th) return; if (typeof th.props !== 'undefined') { column.props = (0, _libFilter_props_from.filterPropsFrom)(th.props); diff --git a/lib/reactable/thead.js b/lib/reactable/thead.js index 3326990b..d423b940 100644 --- a/lib/reactable/thead.js +++ b/lib/reactable/thead.js @@ -120,6 +120,7 @@ var Thead = (function (_React$Component) { var columns = []; _react2['default'].Children.forEach(component.props.children, function (th) { var column = {}; + if (!th) return; if (typeof th.props !== 'undefined') { column.props = (0, _libFilter_props_from.filterPropsFrom)(th.props); diff --git a/src/reactable/thead.jsx b/src/reactable/thead.jsx index cb22821f..d484abea 100644 --- a/src/reactable/thead.jsx +++ b/src/reactable/thead.jsx @@ -9,6 +9,7 @@ export class Thead extends React.Component { let columns = []; React.Children.forEach(component.props.children, th => { var column = {}; + if (!th) return; if (typeof th.props !== 'undefined') { column.props = filterPropsFrom(th.props); diff --git a/tests/reactable_test.jsx b/tests/reactable_test.jsx index 3f633411..cd98a33c 100644 --- a/tests/reactable_test.jsx +++ b/tests/reactable_test.jsx @@ -375,6 +375,26 @@ describe('Reactable', function() { ReactableTestUtils.expectRowText(1, ['', '28', 'Developer']); }); }); + + context("when one of the s is null", function(){ + before(function () { + ReactDOM.render( + + + Test + {null} + + , + ReactableTestUtils.testNode() + ); + }); + + after(ReactableTestUtils.resetTestEnvironment); + + it('renders the table', function() { + expect($('table#table.table')).to.exist; + }); + }); }); describe('Adding a ', function() { From 2bc029c7e554e5680ccda74bafc6d8017f01dfe6 Mon Sep 17 00:00:00 2001 From: Aaron Ryden Date: Tue, 13 Dec 2016 17:39:10 -0500 Subject: [PATCH 6/6] sortable on other fields --- build/reactable.js | 4 ++-- lib/reactable/table.js | 4 ++-- src/reactable/table.jsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build/reactable.js b/build/reactable.js index 9e003aa6..916ab92a 100644 --- a/build/reactable.js +++ b/build/reactable.js @@ -1370,9 +1370,9 @@ window.ReactDOM["default"] = window.ReactDOM; } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }).bind(this)); diff --git a/lib/reactable/table.js b/lib/reactable/table.js index 0cc430da..18c76a2e 100644 --- a/lib/reactable/table.js +++ b/lib/reactable/table.js @@ -377,9 +377,9 @@ var Table = (function (_React$Component) { } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }).bind(this)); diff --git a/src/reactable/table.jsx b/src/reactable/table.jsx index ef401639..37b70bb3 100644 --- a/src/reactable/table.jsx +++ b/src/reactable/table.jsx @@ -337,9 +337,9 @@ export class Table extends React.Component { } else { // Reverse columns if we're doing a reverse sort if (currentSort.direction === 1) { - return this._sortable[currentSort.column](keyA, keyB); + return this._sortable[currentSort.column](keyA, keyB, a, b); } else { - return this._sortable[currentSort.column](keyB, keyA); + return this._sortable[currentSort.column](keyB, keyA, b, a); } } }.bind(this));