Skip to content

Commit

Permalink
fix primefaces#617 fix datatable multisort
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobe91 committed Oct 31, 2018
1 parent 5db5403 commit 76f8149
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/components/datatable/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class DataTable extends Component {

onSort(event) {
let sortField = event.sortField;
let sortOrder = (this.getSortField() === event.sortField) ? this.getSortOrder() * -1 : 1;
let singleSortOrder = (this.getSortField() === event.sortField) ? this.getSortOrder() * -1 : 1;
let multiSortMeta;

this.columnSortable = event.sortable;
Expand All @@ -250,24 +250,30 @@ export class DataTable extends Component {
if(this.props.sortMode === 'multiple') {
let metaKey = event.originalEvent.metaKey || event.originalEvent.ctrlKey;
multiSortMeta = this.getMultiSortMeta();
let sortOrder;
if (multiSortMeta) {
const sortMeta = multiSortMeta.find(sortMeta => sortMeta.field === sortField);
sortOrder = sortMeta ? sortMeta.order * -1 : 1;
} else {
sortOrder = 1;
}
if(!multiSortMeta || !metaKey) {
multiSortMeta = [];
}

this.addSortMeta({field: sortField, order: sortOrder}, multiSortMeta);
}

if (this.props.onSort) {
this.props.onSort({
sortField: sortField,
sortOrder: sortOrder,
sortOrder: singleSortOrder,
multiSortMeta: multiSortMeta
});
}
else {
this.setState({
sortField: sortField,
sortOrder: sortOrder,
sortOrder: singleSortOrder,
first: 0,
multiSortMeta: multiSortMeta
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/datatable/HeaderCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class HeaderCell extends Component {
|| DomHandler.hasClass(targetNode, 'p-sortable-column-icon') || DomHandler.hasClass(targetNode.parentElement, 'p-sortable-column-icon')) {
this.props.onSort({
originalEvent: e,
sortField: this.props.field,
sortField: this.props.sortField ? this.props.sortField : this.props.field,
sortFunction: this.props.sortFunction,
sortable: this.props.sortable
});
Expand Down Expand Up @@ -71,7 +71,7 @@ export class HeaderCell extends Component {
getMultiSortMetaData() {
if(this.props.multiSortMeta) {
for(let i = 0; i < this.props.multiSortMeta.length; i++) {
if(this.props.multiSortMeta[i].field === this.props.field) {
if(this.props.multiSortMeta[i].field === (this.props.sortField ? this.props.sortField : this.props.field)) {
return this.props.multiSortMeta[i];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/datatable/TableHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class TableHeader extends Component {

return React.Children.map(children, (column, i) => {
return <HeaderCell key={i} {...column.props} onSort={this.props.onSort}
sortField={this.props.sortField} sortOrder={this.props.sortOrder} multiSortMeta={this.props.multiSortMeta}
sortOrder={this.props.sortOrder} multiSortMeta={this.props.multiSortMeta}
resizableColumns={this.props.resizableColumns} onColumnResizeStart={this.props.onColumnResizeStart}
onFilter={this.props.onFilter} onHeaderCheckboxClick={this.props.onHeaderCheckboxClick} headerCheckboxSelected={this.props.headerCheckboxSelected}
reorderableColumns={this.props.reorderableColumns} onDragStart={this.props.onColumnDragStart} onDragOver={this.props.onColumnDragOver}
Expand Down

0 comments on commit 76f8149

Please sign in to comment.