Skip to content

Commit b84f953

Browse files
noahsilasdrew-gross
authored andcommitted
Allow sorting by createdAt ascending (#508)
When attempting to sort by the `createdAt` column, we would still apply the default sort ordering of `-createdAt`, meaning that we would specify a sort order of `createdAt,-createdAt`. When Parse-Server gets a sort order in which the same field appears more than once, it will use the last entry for the field in its sorting. This means that the sort the user has selected is overwritten by the default sort we apply. We now check to see if the sort we are applying is already on the `createdAt` field, and if so we do not apply the default ordering. Fixes #447.
1 parent ec68096 commit b84f953

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/dashboard/Data/Browser/Browser.react.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,19 @@ export default class Browser extends DashboardView {
302302

303303
async fetchParseData(source, filters) {
304304
const query = queryFromFilters(source, filters);
305-
if (this.state.ordering[0] === '-') {
306-
query.descending(this.state.ordering.substr(1));
305+
const sortDir = this.state.ordering[0] === '-' ? '-' : '+';
306+
const field = this.state.ordering.substr(sortDir === '-' ? 1 : 0)
307+
308+
if (sortDir === '-') {
309+
query.descending(field)
307310
} else {
308-
query.ascending(this.state.ordering);
311+
query.ascending(field)
309312
}
310-
query.addDescending('createdAt');
313+
314+
if (field !== 'createdAt') {
315+
query.addDescending('createdAt');
316+
}
317+
311318
query.limit(200);
312319
const data = await query.find({ useMasterKey: true });
313320
return data;

0 commit comments

Comments
 (0)