Skip to content

Commit

Permalink
Merge pull request #527 from flamerohr/stop-internal-sort
Browse files Browse the repository at this point in the history
Stop sorting internally if using external sort
  • Loading branch information
blkmutt authored Jan 24, 2017
2 parents d8f7ee8 + bf3e2fe commit 657bc92
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 115 deletions.
109 changes: 54 additions & 55 deletions build/Griddle.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,74 +592,73 @@ return /******/ (function(modules) { // webpackBootstrap

var that = this;

// get the correct page size
if (this.state.sortColumn !== "") {
var column = this.state.sortColumn;
var sortColumn = _filter(this.props.columnMetadata, { columnName: column });
var customCompareFn;
var multiSort = {
columns: [],
orders: []
};
if (!this.props.useExternal) {
if (this.state.sortColumn !== "") {
var column = this.state.sortColumn;
var sortColumn = _filter(this.props.columnMetadata, { columnName: column });
var customCompareFn;
var multiSort = {
columns: [],
orders: []
};

if (sortColumn.length > 0) {
customCompareFn = sortColumn[0].hasOwnProperty("customCompareFn") && sortColumn[0]["customCompareFn"];
if (sortColumn[0]["multiSort"]) {
multiSort = sortColumn[0]["multiSort"];
if (sortColumn.length > 0) {
customCompareFn = sortColumn[0].hasOwnProperty("customCompareFn") && sortColumn[0]["customCompareFn"];
if (sortColumn[0]["multiSort"]) {
multiSort = sortColumn[0]["multiSort"];
}
}
}

if (this.state.sortDirection) {
if (typeof customCompareFn === 'function') {
if (customCompareFn.length === 2) {
data = data.sort(function (a, b) {
return customCompareFn(_get(a, column), _get(b, column));
});

if (this.state.sortDirection === 'desc') {
data.reverse();
if (this.state.sortDirection) {
if (typeof customCompareFn === 'function') {
if (customCompareFn.length === 2) {
data = data.sort(function (a, b) {
return customCompareFn(_get(a, column), _get(b, column));
});

if (this.state.sortDirection === 'desc') {
data.reverse();
}
} else if (customCompareFn.length === 1) {
data = _orderBy(data, function (item) {
return customCompareFn(_get(item, column));
}, [this.state.sortDirection]);
}
} else if (customCompareFn.length === 1) {
data = _orderBy(data, function (item) {
return customCompareFn(_get(item, column));
}, [this.state.sortDirection]);
}
} else {
var iteratees = [function (row) {
return (_get(row, column) || '').toString().toLowerCase();
}];
var orders = [this.state.sortDirection];
multiSort.columns.forEach(function (col, i) {
iteratees.push(function (row) {
return (_get(row, col) || '').toString().toLowerCase();
} else {
var iteratees = [function (row) {
return (_get(row, column) || '').toString().toLowerCase();
}];
var orders = [this.state.sortDirection];
multiSort.columns.forEach(function (col, i) {
iteratees.push(function (row) {
return (_get(row, col) || '').toString().toLowerCase();
});
if (multiSort.orders[i] === 'asc' || multiSort.orders[i] === 'desc') {
orders.push(multiSort.orders[i]);
} else {
orders.push(_this.state.sortDirection);
}
});
if (multiSort.orders[i] === 'asc' || multiSort.orders[i] === 'desc') {
orders.push(multiSort.orders[i]);
} else {
orders.push(_this.state.sortDirection);
}
});

data = _orderBy(data, iteratees, orders);
data = _orderBy(data, iteratees, orders);
}
}
}
}

var currentPage = this.getCurrentPage();
var currentPage = this.getCurrentPage();

if (!this.props.useExternal && pageList && this.state.resultsPerPage * (currentPage + 1) <= this.state.resultsPerPage * this.state.maxPage && currentPage >= 0) {
if (this.isInfiniteScrollEnabled()) {
// If we're doing infinite scroll, grab all results up to the current page.
data = first(data, (currentPage + 1) * this.state.resultsPerPage);
} else {
//the 'rest' is grabbing the whole array from index on and the 'initial' is getting the first n results
var rest = drop(data, currentPage * this.state.resultsPerPage);
data = (dropRight || initial)(rest, rest.length - this.state.resultsPerPage);
if (!this.props.useExternal && pageList && this.state.resultsPerPage * (currentPage + 1) <= this.state.resultsPerPage * this.state.maxPage && currentPage >= 0) {
if (this.isInfiniteScrollEnabled()) {
// If we're doing infinite scroll, grab all results up to the current page.
data = first(data, (currentPage + 1) * this.state.resultsPerPage);
} else {
//the 'rest' is grabbing the whole array from index on and the 'initial' is getting the first n results
var rest = drop(data, currentPage * this.state.resultsPerPage);
data = (dropRight || initial)(rest, rest.length - this.state.resultsPerPage);
}
}
}

var meta = this.columnSettings.getMetadataColumns;

var transformedData = [];

for (var i = 0; i < data.length; i++) {
Expand Down
111 changes: 55 additions & 56 deletions modules/griddle.jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,74 +529,73 @@ var Griddle = React.createClass({

var that = this;

// get the correct page size
if (this.state.sortColumn !== "") {
var column = this.state.sortColumn;
var sortColumn = _filter(this.props.columnMetadata, { columnName: column });
var customCompareFn;
var multiSort = {
columns: [],
orders: []
};

if (sortColumn.length > 0) {
customCompareFn = sortColumn[0].hasOwnProperty("customCompareFn") && sortColumn[0]["customCompareFn"];
if (sortColumn[0]["multiSort"]) {
multiSort = sortColumn[0]["multiSort"];
if (!this.props.useExternal) {
if (this.state.sortColumn !== "") {
var column = this.state.sortColumn;
var sortColumn = _filter(this.props.columnMetadata, { columnName: column });
var customCompareFn;
var multiSort = {
columns: [],
orders: []
};

if (sortColumn.length > 0) {
customCompareFn = sortColumn[0].hasOwnProperty("customCompareFn") && sortColumn[0]["customCompareFn"];
if (sortColumn[0]["multiSort"]) {
multiSort = sortColumn[0]["multiSort"];
}
}
}

if (this.state.sortDirection) {
if (typeof customCompareFn === 'function') {
if (customCompareFn.length === 2) {
data = data.sort(function (a, b) {
return customCompareFn(_get(a, column), _get(b, column));
});

if (this.state.sortDirection === 'desc') {
data.reverse();
if (this.state.sortDirection) {
if (typeof customCompareFn === 'function') {
if (customCompareFn.length === 2) {
data = data.sort(function (a, b) {
return customCompareFn(_get(a, column), _get(b, column));
});

if (this.state.sortDirection === 'desc') {
data.reverse();
}
} else if (customCompareFn.length === 1) {
data = _orderBy(data, function (item) {
return customCompareFn(_get(item, column));
}, [this.state.sortDirection]);
}
} else if (customCompareFn.length === 1) {
data = _orderBy(data, function (item) {
return customCompareFn(_get(item, column));
}, [this.state.sortDirection]);
}
} else {
var iteratees = [function (row) {
return (_get(row, column) || '').toString().toLowerCase();
}];
var orders = [this.state.sortDirection];
multiSort.columns.forEach(function (col, i) {
iteratees.push(function (row) {
return (_get(row, col) || '').toString().toLowerCase();
} else {
var iteratees = [function (row) {
return (_get(row, column) || '').toString().toLowerCase();
}];
var orders = [this.state.sortDirection];
multiSort.columns.forEach(function (col, i) {
iteratees.push(function (row) {
return (_get(row, col) || '').toString().toLowerCase();
});
if (multiSort.orders[i] === 'asc' || multiSort.orders[i] === 'desc') {
orders.push(multiSort.orders[i]);
} else {
orders.push(_this.state.sortDirection);
}
});
if (multiSort.orders[i] === 'asc' || multiSort.orders[i] === 'desc') {
orders.push(multiSort.orders[i]);
} else {
orders.push(_this.state.sortDirection);
}
});

data = _orderBy(data, iteratees, orders);
data = _orderBy(data, iteratees, orders);
}
}
}
}

var currentPage = this.getCurrentPage();
var currentPage = this.getCurrentPage();

if (!this.props.useExternal && pageList && this.state.resultsPerPage * (currentPage + 1) <= this.state.resultsPerPage * this.state.maxPage && currentPage >= 0) {
if (this.isInfiniteScrollEnabled()) {
// If we're doing infinite scroll, grab all results up to the current page.
data = first(data, (currentPage + 1) * this.state.resultsPerPage);
} else {
//the 'rest' is grabbing the whole array from index on and the 'initial' is getting the first n results
var rest = drop(data, currentPage * this.state.resultsPerPage);
data = (dropRight || initial)(rest, rest.length - this.state.resultsPerPage);
if (!this.props.useExternal && pageList && this.state.resultsPerPage * (currentPage + 1) <= this.state.resultsPerPage * this.state.maxPage && currentPage >= 0) {
if (this.isInfiniteScrollEnabled()) {
// If we're doing infinite scroll, grab all results up to the current page.
data = first(data, (currentPage + 1) * this.state.resultsPerPage);
} else {
//the 'rest' is grabbing the whole array from index on and the 'initial' is getting the first n results
var rest = drop(data, currentPage * this.state.resultsPerPage);
data = (dropRight || initial)(rest, rest.length - this.state.resultsPerPage);
}
}
}

var meta = this.columnSettings.getMetadataColumns;

var transformedData = [];

for (var i = 0; i < data.length; i++) {
Expand Down
7 changes: 3 additions & 4 deletions scripts/griddle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ var Griddle = React.createClass({
getDataForRender: function(data, cols, pageList){
var that = this;

// get the correct page size
if(this.state.sortColumn !== "") {
if (!this.props.useExternal) {
if (this.state.sortColumn !== "") {
var column = this.state.sortColumn;
var sortColumn = _filter(this.props.columnMetadata, {columnName: column});
var customCompareFn;
Expand Down Expand Up @@ -599,8 +599,7 @@ var Griddle = React.createClass({
data = (dropRight || initial)(rest, rest.length-this.state.resultsPerPage);
}
}

var meta = this.columnSettings.getMetadataColumns;
}

var transformedData = [];

Expand Down

0 comments on commit 657bc92

Please sign in to comment.