diff --git a/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js b/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js
index 13cc03e3b7..bac704bc12 100644
--- a/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js
+++ b/js/apps/system/aardvark/frontend/js/collections/arangoDocuments.js
@@ -8,6 +8,8 @@
filters: [],
+ sortAttribute: "_key",
+
url: '/_api/documents',
model: window.arangoDocumentModel,
@@ -33,6 +35,14 @@
this.loadTotal();
},
+ setSort: function(key) {
+ this.sortAttribute = key;
+ },
+
+ getSort: function() {
+ return this.sortAttribute;
+ },
+
addFilter: function(attr, op, val) {
this.filters.push({
attr: attr,
@@ -83,9 +93,11 @@
query = "FOR x in @@collection";
query += this.setFiltersForQuery(bindVars);
// Sort result, only useful for a small number of docs
- if (this.getTotal() < 10000) {
- query += " SORT TO_NUMBER(x._key) == 0 ? x._key : TO_NUMBER(x._key)";
+ if (this.getTotal() < 12000) {
+ query += " SORT TO_NUMBER(x." + this.getSort() + ") == 0 ? x."
+ + this.getSort() + " : TO_NUMBER(x." + this.getSort() + ")";
}
+
if (bindVars.count !== 'all') {
query += " LIMIT @offset, @count RETURN x";
}
diff --git a/js/apps/system/aardvark/frontend/js/templates/documentsView.ejs b/js/apps/system/aardvark/frontend/js/templates/documentsView.ejs
index f61a9165e7..e9ed6d5a25 100644
--- a/js/apps/system/aardvark/frontend/js/templates/documentsView.ejs
+++ b/js/apps/system/aardvark/frontend/js/templates/documentsView.ejs
@@ -51,9 +51,11 @@
-
-
-
+
+
+
+
+
Sort by:
diff --git a/js/apps/system/aardvark/frontend/js/views/documentsView.js b/js/apps/system/aardvark/frontend/js/views/documentsView.js
index d2670bfedd..548da8a083 100644
--- a/js/apps/system/aardvark/frontend/js/views/documentsView.js
+++ b/js/apps/system/aardvark/frontend/js/views/documentsView.js
@@ -87,7 +87,8 @@
"click #documentsToolbar ul" : "resetIndexForms",
"click #indexHeader #addIndex" : "toggleNewIndexView",
"click #indexHeader #cancelIndex" : "toggleNewIndexView",
- "change #documentSize" : "setPagesize"
+ "change #documentSize" : "setPagesize",
+ "change #docsSort" : "setSorting"
},
showSpinner: function() {
@@ -112,7 +113,20 @@
this.collection.getDocuments(this.getDocsCallback.bind(this));
},
+ setSorting: function() {
+ var sortAttribute = $('#docsSort').val();
+
+ if (sortAttribute === '' || sortAttribute === undefined || sortAttribute === null) {
+ sortAttribute = '_key';
+ }
+
+ this.collection.setSort(sortAttribute);
+ },
+
returnPressedHandler: function(event) {
+ if (event.keyCode === 13 && $(event.target).is($('#docsSort'))) {
+ this.collection.getDocuments(this.getDocsCallback.bind(this));
+ }
if (event.keyCode === 13) {
if ($("#confirmDeleteBtn").attr("disabled") === false) {
this.confirmDelete();
@@ -334,6 +348,7 @@
var self = this, counter = 0;
this.filterId = 0;
+ $('#docsSort').val(this.collection.getSort());
_.each(this.restoredFilters, function (f) {
//change html here and restore filters
if (counter !== 0) {
@@ -767,6 +782,7 @@
else {
if (this.lastCollectionName !== undefined) {
this.collection.resetFilter();
+ this.collection.setSort('_key');
this.restoredFilters = [];
this.activeFilter = false;
}