Skip to content

Commit

Permalink
PoC - 6pac#546 - broken multi-column-sort on invisible columns resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
arash dalir committed Oct 28, 2020
1 parent e1da4ca commit 9572182
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion slick.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ if (typeof Slick === "undefined") {
var sortColumns = [];
var columnPosLeft = [];
var columnPosRight = [];
var allColumns = [];

var pagingActive = false;
var pagingIsLastPage = false;
Expand Down Expand Up @@ -1409,7 +1410,8 @@ if (typeof Slick === "undefined") {
trigger(self.onSort, {
multiColumnSort: true,
sortCols: $.map(sortColumns, function(col) {
return {columnId: columns[getColumnIndex(col.columnId)].id, sortCol: columns[getColumnIndex(col.columnId)], sortAsc: col.sortAsc };
var column = getColumnById(col.columnId, false);
return {columnId: column && column.id, sortCol: column, sortAsc: col.sortAsc };
})
}, e);
}
Expand Down Expand Up @@ -2726,6 +2728,23 @@ if (typeof Slick === "undefined") {
return columns;
}

function getColumnById(columnId, useOnlyVisibleColumns){
var columnList = useOnlyVisibleColumns?getColumns():getAllColumns(true);

var column = null;

for(var c = 0; c < columnList.length; c++)
{
if (columnList[c].id === columnId)
{
column = columnList[c];
break;
}
}

return column;
}

function updateColumnCaches() {
// Pre-calculate cell boundaries.
columnPosLeft = [];
Expand Down Expand Up @@ -2765,6 +2784,31 @@ if (typeof Slick === "undefined") {
}
}

function setAllColumns(columnDefinitions){
var _columns = columns.slice(0);
var _initialized = initialized;

initialized = false;
setColumns(columnDefinitions);
allColumns = columns.slice(0);
columns = _columns;
initialized = _initialized;
}

/**
*
* @param {boolean} [defaultToColumns=true]
* @return {[]|Array}
*/
function getAllColumns(defaultToColumns){
if (typeof defaultToColumns === typeof undefined)
{
defaultToColumns = true;
}

return defaultToColumns?(allColumns.length?allColumns:columns):allColumns;
}

function setColumns(columnDefinitions) {
var _treeColumns = new Slick.TreeColumns(columnDefinitions);
if (_treeColumns.hasDepth()) {
Expand Down Expand Up @@ -5851,6 +5895,9 @@ if (typeof Slick === "undefined") {
"getPluginByName": getPluginByName,
"getColumns": getColumns,
"setColumns": setColumns,
"getAllColumns": getAllColumns,
"setAllColumns": setAllColumns,
"getColumnById": getColumnById,
"getColumnIndex": getColumnIndex,
"updateColumnHeader": updateColumnHeader,
"setSortColumn": setSortColumn,
Expand Down

0 comments on commit 9572182

Please sign in to comment.