From 62539e36f9da22f38b9848118ed50791f6cf4340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pigeon?= Date: Wed, 23 Nov 2016 15:19:00 +0100 Subject: [PATCH] [8.0] render axis values in received order --- web_widget_x2many_2d_matrix/README.rst | 1 + .../static/src/js/web_widget_x2many_2d_matrix.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/web_widget_x2many_2d_matrix/README.rst b/web_widget_x2many_2d_matrix/README.rst index a22f8e00..377291d9 100644 --- a/web_widget_x2many_2d_matrix/README.rst +++ b/web_widget_x2many_2d_matrix/README.rst @@ -28,6 +28,7 @@ result could look like this: The beauty of this is that you have an arbitrary amount of columns with this widget, trying to get this in standard x2many lists involves some quite ugly hacks. +Note: The order of axis values depends on their order in the matrix you provide. Usage ===== diff --git a/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js b/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js index 88ba1745..e438c47e 100644 --- a/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js +++ b/web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js @@ -14,6 +14,8 @@ openerp.web_widget_x2many_2d_matrix = function(instance) // those will be filled with rows from the dataset by_x_axis: {}, by_y_axis: {}, + by_x_axis_sorted: [], + by_y_axis_sorted: [], by_id: {}, // configuration values field_x_axis: 'x', @@ -76,6 +78,8 @@ openerp.web_widget_x2many_2d_matrix = function(instance) var self = this, result = this._super.apply(this, arguments); + self.by_x_axis_sorted = [] + self.by_y_axis_sorted = [] self.by_x_axis = {}; self.by_y_axis = {}; self.by_id = {}; @@ -206,6 +210,10 @@ openerp.web_widget_x2many_2d_matrix = function(instance) } return true; }); + if(this.by_x_axis_sorted.indexOf(x) == -1) + this.by_x_axis_sorted.push(x) + if(this.by_y_axis_sorted.indexOf(y) == -1) + this.by_y_axis_sorted.push(y) this.by_x_axis[x] = this.by_x_axis[x] || {}; this.by_y_axis[y] = this.by_y_axis[y] || {}; this.by_x_axis[x][y] = row; @@ -216,13 +224,13 @@ openerp.web_widget_x2many_2d_matrix = function(instance) // get x axis values in the correct order get_x_axis_values: function() { - return _.keys(this.by_x_axis); + return this.by_x_axis_sorted }, // get y axis values in the correct order get_y_axis_values: function() { - return _.keys(this.by_y_axis); + return this.by_y_axis_sorted }, // get the label for a value on the x axis