Skip to content

Commit

Permalink
feat(picker): Column Picker expose init to use by translation
Browse files Browse the repository at this point in the history
- exposing the init() function helps dealing with i18n translation without losing any Slick.Event attached like onColumnsChanged
  • Loading branch information
ghiscoding committed Jun 20, 2018
1 parent 037acaa commit 6fc6eea
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions controls/slick.columnpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 28,7 @@

(function ($) {
function SlickColumnPicker(columns, grid, options) {
var _grid = grid;
var $list;
var $menu;
var columnCheckboxes;
Expand All @@ -43,7 44,7 @@
syncResizeTitle: "Synchronous resize"
};

function init() {
function init(grid) {
grid.onHeaderContextMenu.subscribe(handleHeaderContextMenu);
grid.onColumnsReordered.subscribe(updateColumnOrder);
options = $.extend({}, defaults, options);
Expand All @@ -69,8 70,8 @@
}

function destroy() {
grid.onHeaderContextMenu.unsubscribe(handleHeaderContextMenu);
grid.onColumnsReordered.unsubscribe(updateColumnOrder);
_grid.onHeaderContextMenu.unsubscribe(handleHeaderContextMenu);
_grid.onColumnsReordered.unsubscribe(updateColumnOrder);
$(document.body).off("mousedown", handleBodyMouseDown);
$("div.slick-columnpicker").hide(options.fadeSpeed);
$menu.remove();
Expand All @@ -94,7 95,7 @@
$input = $("<input type='checkbox' />").data("column-id", columns[i].id);
columnCheckboxes.push($input);

if (grid.getColumnIndex(columns[i].id) != null) {
if (_grid.getColumnIndex(columns[i].id) != null) {
$input.attr("checked", "checked");
}

Expand All @@ -116,7 117,7 @@
.text(forceFitTitle)
.prepend($input)
.appendTo($li);
if (grid.getOptions().forceFitColumns) {
if (_grid.getOptions().forceFitColumns) {
$input.attr("checked", "checked");
}
}
Expand All @@ -129,7 130,7 @@
.text(syncResizeTitle)
.prepend($input)
.appendTo($li);
if (grid.getOptions().syncColumnCellResize) {
if (_grid.getOptions().syncColumnCellResize) {
$input.attr("checked", "checked");
}
}
Expand All @@ -150,10 151,10 @@
// We create a new `columns` structure by leaving currently-hidden
// columns in their original ordinal position and interleaving the results
// of the current column sort.
var current = grid.getColumns().slice(0);
var current = _grid.getColumns().slice(0);
var ordered = new Array(columns.length);
for (var i = 0; i < ordered.length; i ) {
if ( grid.getColumnIndex(columns[i].id) === undefined ) {
if ( _grid.getColumnIndex(columns[i].id) === undefined ) {
// If the column doesn't return a value from getColumnIndex,
// it is hidden. Leave it in this position.
ordered[i] = columns[i];
Expand All @@ -168,19 169,19 @@
function updateColumn(e) {
if ($(e.target).data("option") == "autoresize") {
if (e.target.checked) {
grid.setOptions({forceFitColumns:true});
grid.autosizeColumns();
_grid.setOptions({forceFitColumns:true});
_grid.autosizeColumns();
} else {
grid.setOptions({forceFitColumns:false});
_grid.setOptions({forceFitColumns:false});
}
return;
}

if ($(e.target).data("option") == "syncresize") {
if (e.target.checked) {
grid.setOptions({syncColumnCellResize:true});
_grid.setOptions({syncColumnCellResize:true});
} else {
grid.setOptions({syncColumnCellResize:false});
_grid.setOptions({syncColumnCellResize:false});
}
return;
}
Expand All @@ -198,18 199,19 @@
return;
}

grid.setColumns(visibleColumns);
onColumnsChanged.notify({columns: visibleColumns, grid: grid});
_grid.setColumns(visibleColumns);
onColumnsChanged.notify({columns: visibleColumns, grid: _grid});
}
}

function getAllColumns() {
return columns;
}

init();
init(_grid);

return {
"init": init,
"getAllColumns": getAllColumns,
"destroy": destroy,
"onColumnsChanged": onColumnsChanged
Expand Down

0 comments on commit 6fc6eea

Please sign in to comment.