From c39563b1409540e17e66d4bf3baf68d46ea93d62 Mon Sep 17 00:00:00 2001
From: legac <renaud.legac@free.fr>
Date: Tue, 11 Feb 2014 23:01:41 +0100
Subject: [PATCH] Add the logic to sort the grid content remotely when
 remoteAction is true.

---
 static/plugin_dbui/src/grid/Panel.js | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/static/plugin_dbui/src/grid/Panel.js b/static/plugin_dbui/src/grid/Panel.js
index 92a29e7c..9fd60b7a 100644
--- a/static/plugin_dbui/src/grid/Panel.js
+++ b/static/plugin_dbui/src/grid/Panel.js
@@ -43,11 +43,18 @@ Ext.define('App.grid.Panel', {
         // At that step the plugins are not yet instantiate.
         // Thus wait the last moment.
         this.on('beforerender', this.onBeforeRender, this);
+
+        // Reload he store when sort condition changed and
+        // when the remoteAction is true
+        this.on('sortchange', this.onSort, this);
     },
 
     // Private method requires by the Ext JS component model
     beforeDestroy: function () {
 
+        this.un('beforerender', this.onBeforeRender, this);
+        this.un('sortchange', this.onSort, this);
+
         // reset the store
         this.reset();
 
@@ -95,5 +102,24 @@ Ext.define('App.grid.Panel', {
             store.clearFilter();
             store.filter();
         }
+    },
+
+    /**
+     * Reload the store applying sort condition selected by the user.
+     * Do nothing when #remoteAction is false.
+     *
+     * @param {Ext.grid.header.Container} ct
+     * @param {Ext.grid.column.Column} column
+     * @param {String} direction
+     * @param {Object} eOpts
+     *
+     */
+    onSort: function (ct, column, direction, eOpts) {
+
+        "use strict";
+
+        if (this.remoteAction) {
+            this.getStore().loadPage(1);
+        }
     }
 });
-- 
GitLab