diff --git a/web_graph_sort/static/src/js/web_graph_sort.js b/web_graph_sort/static/src/js/web_graph_sort.js index 0a7d46a2..d5769780 100644 --- a/web_graph_sort/static/src/js/web_graph_sort.js +++ b/web_graph_sort/static/src/js/web_graph_sort.js @@ -20,36 +20,48 @@ openerp.web_graph_sort = function(instance) { draw_measure_row: function (measure_row) { var $row = $('').append(''); var self = this; + + var measures = _.unique(_.map(measure_row, function(cell){return cell.text;})); + var measure_index = _.indexBy(self.measure_list, 'string'); + + var first_total_index = measure_row.length - measures.length; + var column_index = 0; + _.each(measure_row, function (cell) { - _.each(self.measure_list,function(item){ - if(item.string === cell.text) { - var data_id; - if ( - self.pivot.sort !== null && - self.pivot.sort[0].indexOf(item.field) >= 0 && - self.pivot.sort[0].indexOf('-') === -1 - ){ - data_id = "-" + item.field; - } - else { - data_id = item.field; - } + var item = measure_index[cell.text]; + if(item){ + var data_id; + if ( + self.pivot.sort !== null && + self.pivot.sort[0].indexOf(item.field) >= 0 && + self.pivot.sort[0].indexOf('-') === -1 + ){ + data_id = "-" + item.field; + } + else { + data_id = item.field; + } - var $cell = $('') - .addClass('measure_row') - .addClass('oe_sortable') - .attr('data-id', data_id) - .append("
" + cell.text + "
"); + var $cell = $('') + .addClass('measure_row') + .addClass('oe_sortable') + .attr('data-id', data_id) + .append("
" + cell.text + "
"); - if (cell.is_bold) { - $cell.css('font-weight', 'bold'); - } - if (self.pivot.sort !== null && self.pivot.sort[0].indexOf(item.field) >= 0) { - $cell.addClass((self.pivot.sort[0].indexOf('-') === -1) ? "sortdown":"sortup"); - } - $row.append($cell); + if (cell.is_bold) { + $cell.css('font-weight', 'bold'); } - }); + + if ( + column_index >= first_total_index && + self.pivot.sort !== null && + self.pivot.sort[0].indexOf(item.field) >= 0 + ) { + $cell.addClass((self.pivot.sort[0].indexOf('-') === -1) ? "sortdown": "sortup"); + } + column_index += 1; + } + $row.append($cell); }); this.$thead.append($row); },