Skip to content

Commit

Permalink
Fixed Bug:1382372
Browse files Browse the repository at this point in the history
BUG: On chrome, the grid rows when rendered for the first time were sorted in a random way where first row was getting swapped with another row placed halfway.
ISSUE: This was introduced with defaultSort option added which used to perform sort unnecessarily and changed the behaviour of rows on chrome
FIX: Added a check to perform default sort of grid only when the length of defaultSortCols > 0

Change-Id: I85e39e1229c91fb7f0fb1e638ec3d26bf25d85be
  • Loading branch information
Sagar Gala committed Dec 11, 2014
1 parent 4a788cf commit 8b8e8b7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions webroot/js/slickgrid-utils.js
Expand Up @@ -709,7 +709,7 @@ function getDefaultGridConfig() {
//Refresh the grid only if it's not destroyed
setTimeout(function(){
if($(gridContainer).data('contrailGrid')) {
var checkedRows = gridContainer.data('contrailGrid').getCheckedRows();
var checkedRows = gridContainer.data('contrailGrid').getCheckedRows();
grid.invalidateAllRows();
grid.render();
if(contrail.checkIfFunction(gridDataSource.events.onDataBoundCB)) {
Expand Down Expand Up @@ -747,7 +747,7 @@ function getDefaultGridConfig() {
eventHandlerMap.dataView['onUpdateData'] = function () {
//Refresh the grid only if it's not destroyed
if($(gridContainer).data('contrailGrid')) {
grid.invalidateAllRows();
grid.invalidateAllRows();
grid.updateRowCount();
grid.render();
if(contrail.checkIfFunction(gridDataSource.events.onUpdateDataCB)) {
Expand Down Expand Up @@ -775,19 +775,21 @@ function getDefaultGridConfig() {
};

function performSort(cols) {
dataView.sort(function (dataRow1, dataRow2) {
for (var i = 0, l = cols.length; i < l; i++) {
var field = cols[i].sortCol.field;
var sign = cols[i].sortAsc ? 1 : -1;
var value1 = (contrail.checkIfExist(cols[i].sortCol.sortable.sortBy) && cols[i].sortCol.sortable.sortBy == 'formattedValue') ? cols[i].sortCol.formatter('','','','',dataRow1) : dataRow1[field],
value2 = (contrail.checkIfExist(cols[i].sortCol.sortable.sortBy) && cols[i].sortCol.sortable.sortBy == 'formattedValue') ? cols[i].sortCol.formatter('','','','',dataRow2) : dataRow2[field];
var result = (value1 == value2 ? 0 : (value1 > value2 ? 1 : -1)) * sign;
if (result != 0) {
return result;
if(cols.length > 0) {
dataView.sort(function (dataRow1, dataRow2) {
for (var i = 0, l = cols.length; i < l; i++) {
var field = cols[i].sortCol.field;
var sign = cols[i].sortAsc ? 1 : -1;
var value1 = (contrail.checkIfExist(cols[i].sortCol.sortable.sortBy) && cols[i].sortCol.sortable.sortBy == 'formattedValue') ? cols[i].sortCol.formatter('', '', '', '', dataRow1) : dataRow1[field],
value2 = (contrail.checkIfExist(cols[i].sortCol.sortable.sortBy) && cols[i].sortCol.sortable.sortBy == 'formattedValue') ? cols[i].sortCol.formatter('', '', '', '', dataRow2) : dataRow2[field];
var result = (value1 == value2 ? 0 : (value1 > value2 ? 1 : -1)) * sign;
if (result != 0) {
return result;
}
}
}
return 0;
});
return 0;
});
}
};

function initSearchBox() {
Expand Down

0 comments on commit 8b8e8b7

Please sign in to comment.