Skip to content

Commit a0d6f25

Browse files
authored
Merge pull request glittershark#298 from tjphopkins/new_props
Call initialize methods with new props
2 parents 55a166e + 3559322 commit a0d6f25

File tree

4 files changed

+74
-18
lines changed

4 files changed

+74
-18
lines changed

build/reactable.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,11 +1141,11 @@ window.ReactDOM["default"] = window.ReactDOM;
11411141
}
11421142
}, {
11431143
key: 'initializeFilters',
1144-
value: function initializeFilters() {
1144+
value: function initializeFilters(props) {
11451145
this._filterable = {};
11461146
// Transform filterable properties into a more friendly list
1147-
for (var i in this.props.filterable) {
1148-
var column = this.props.filterable[i];
1147+
for (var i in props.filterable) {
1148+
var column = props.filterable[i];
11491149
var columnName = undefined,
11501150
filterFunction = undefined;
11511151

@@ -1172,11 +1172,11 @@ window.ReactDOM["default"] = window.ReactDOM;
11721172
}
11731173
}, {
11741174
key: 'initializeSorts',
1175-
value: function initializeSorts() {
1175+
value: function initializeSorts(props) {
11761176
this._sortable = {};
11771177
// Transform sortable properties into a more friendly list
1178-
for (var i in this.props.sortable) {
1179-
var column = this.props.sortable[i];
1178+
for (var i in props.sortable) {
1179+
var column = props.sortable[i];
11801180
var columnName = undefined,
11811181
sortFunction = undefined;
11821182

lib/reactable/table.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ var Table = (function (_React$Component) {
172172
}
173173
}, {
174174
key: 'initializeFilters',
175-
value: function initializeFilters() {
175+
value: function initializeFilters(props) {
176176
this._filterable = {};
177177
// Transform filterable properties into a more friendly list
178-
for (var i in this.props.filterable) {
179-
var column = this.props.filterable[i];
178+
for (var i in props.filterable) {
179+
var column = props.filterable[i];
180180
var columnName = undefined,
181181
filterFunction = undefined;
182182

@@ -203,11 +203,11 @@ var Table = (function (_React$Component) {
203203
}
204204
}, {
205205
key: 'initializeSorts',
206-
value: function initializeSorts() {
206+
value: function initializeSorts(props) {
207207
this._sortable = {};
208208
// Transform sortable properties into a more friendly list
209-
for (var i in this.props.sortable) {
210-
var column = this.props.sortable[i];
209+
for (var i in props.sortable) {
210+
var column = props.sortable[i];
211211
var columnName = undefined,
212212
sortFunction = undefined;
213213

src/reactable/table.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ export class Table extends React.Component {
136136
this.initializeFilters(props);
137137
}
138138

139-
initializeFilters() {
139+
initializeFilters(props) {
140140
this._filterable = {};
141141
// Transform filterable properties into a more friendly list
142-
for (let i in this.props.filterable) {
143-
let column = this.props.filterable[i];
142+
for (let i in props.filterable) {
143+
let column = props.filterable[i];
144144
let columnName, filterFunction;
145145

146146
if (column instanceof Object) {
@@ -165,11 +165,11 @@ export class Table extends React.Component {
165165
}
166166
}
167167

168-
initializeSorts() {
168+
initializeSorts(props) {
169169
this._sortable = {};
170170
// Transform sortable properties into a more friendly list
171-
for (let i in this.props.sortable) {
172-
let column = this.props.sortable[i];
171+
for (let i in props.sortable) {
172+
let column = props.sortable[i];
173173
let columnName, sortFunction;
174174

175175
if (column instanceof Object) {

tests/reactable_test.jsx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,62 @@ describe('Reactable', function() {
14191419
});
14201420
});
14211421

1422+
describe('sorting after updating columns and sortable props', () => {
1423+
let parent;
1424+
1425+
before(function () {
1426+
var TestParent = React.createFactory(React.createClass({
1427+
getInitialState: function() {
1428+
return ({
1429+
data: [
1430+
{Name: 'Lee Salminen', Age: '23', Position: 'Programmer'},
1431+
{Name: 'Griffin Smith', Age: '18', Position: 'Engineer'},
1432+
{Name: 'Ian Zhang', Age: '28', Position: 'Developer'}
1433+
],
1434+
sortable: ['Name', 'Age', 'Position'],
1435+
defaultSort: 'Position'
1436+
});
1437+
},
1438+
1439+
render: function() {
1440+
return (
1441+
<Reactable.Table
1442+
className="table"
1443+
id="table"
1444+
data={this.state.data}
1445+
sortable={this.state.sortable}
1446+
defaultSort={this.state.defaultSort}
1447+
/>
1448+
)
1449+
}
1450+
}));
1451+
1452+
parent = ReactDOM.render(TestParent(), ReactableTestUtils.testNode());
1453+
});
1454+
1455+
after(ReactableTestUtils.resetTestEnvironment);
1456+
1457+
it('sorts on new column after receiving new props', function() {
1458+
const newData = [
1459+
{ Name: 'Lee Salminen', Age: '23', newColumn: 'Programmer'},
1460+
{ Name: 'Griffin Smith', Age: '18', newColumn: 'Engineer'},
1461+
{ Name: 'Ian Zhang', Age: '28', newColumn: 'Developer'}
1462+
]
1463+
const newSortable = ['Name', 'Age', 'newColumn']
1464+
const newDefaultSort = 'newColumn'
1465+
parent.setState({data: newData, sortable: newSortable, defaultSort: newDefaultSort});
1466+
var positionHeader = $('#table thead tr.reactable-column-header th')[2];
1467+
ReactTestUtils.Simulate.click(positionHeader);
1468+
1469+
ReactableTestUtils.expectRowText(1, ['Griffin Smith', '18', 'Engineer']);
1470+
ReactableTestUtils.expectRowText(2, ['Lee Salminen', '23', 'Programmer']);
1471+
ReactableTestUtils.expectRowText(0, ['Ian Zhang', '28', 'Developer']);
1472+
1473+
// Make sure the headers have the right classes
1474+
expect($(positionHeader)).to.have.class('reactable-header-sort-asc');
1475+
});
1476+
});
1477+
14221478
describe('sort descending by default flag', function(){
14231479
before(function() {
14241480
ReactDOM.render(

0 commit comments

Comments
 (0)