Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Overload sortable fn to give access to row data #346

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions build/reactable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,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) {
Expand All @@ -1286,13 +1291,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',
Expand Down Expand Up @@ -1358,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));
Expand Down
18 changes: 15 additions & 3 deletions lib/reactable/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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',
Expand Down Expand Up @@ -365,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));
Expand Down
20 changes: 17 additions & 3 deletions src/reactable/table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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) {
Expand Down Expand Up @@ -323,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));
Expand Down