slickgrid

Slickgrid: How to exclude checkboxSelectColumn from columnPicker


Is there an easy way to exclude the column created by Slick.CheckboxSelectColumn from the column Picker?

With regular columns, you can include excludeFromColumnPicker: true in the column definition but that doesn't seem to work with the checkbox-column.

var checkboxSelector = new Slick.CheckboxSelectColumn(
   { cssClass: "slick-cell-checkboxsel", 
     excludeFromColumnPicker: true // this doesn't seem to work
   });

I also tried excluding the column before passing the column definition array to the columnPicker, like this:

var columnPickerColumns = myColumns.filter(
   (column) => column.id !== "_checkbox_selector"
);

var columnpicker = new Slick.Controls.ColumnPicker(
   columnPickerColumns,
   grid,
   options
);

When passing columnPickerColumns, the checkbox column is missing, but somehow the checkbox column still appears in the column picker.


Solution

  • The reason is because the checkbox column gets created dynamically through the function getColumnDefinition() (shown below) which is inside slick.checkboxselectcolumn.js file at this line number

    function getColumnDefinition() {
          return {
            id: _options.columnId,
            name: (_options.hideSelectAllCheckbox || _options.hideInColumnTitleRow) ? "" : "<input id='header-selector" + _selectAll_UID + "' type='checkbox'><label for='header-selector" + _selectAll_UID + "'></label>",
            toolTip: (_options.hideSelectAllCheckbox || _options.hideInColumnTitleRow) ? "" : _options.toolTip,
            field: "sel",
            width: _options.width,
            resizable: false,
            sortable: false,
            cssClass: _options.cssClass,
            hideSelectAllCheckbox: _options.hideSelectAllCheckbox,
            formatter: checkboxSelectionFormatter
          };
        }
    

    and it's basically missing any of the exclude flags in there. I think this could be a great contributions that you could make to the project by creating a new PR (pull request) and add all necessary flags.

    Just for comparison, I have the same plugin in Slickgrid-Universal and I added a few more flags as can be seen on this line

      getColumnDefinition(): Column {
        return {
          // ....
          excludeFromExport: true,
          excludeFromColumnPicker: true,
          excludeFromGridMenu: true,
          excludeFromQuery: true,
          excludeFromHeaderMenu: true,
      };
    }
    

    Again I would suggest you to make a contribution to the project since I'm not using it myself because I have my own plugins. Perhaps you could improve on that and make it as an option like you provided in your question (excludeFromColumnPicker: _options.excludeFromColumnPicker || false).

    Also note that I'm a major collaborator to the project and we released v4.0 recently, which is removing jQuery, and are not supporting older versions (on 6pac/SlickGrid fork that is)

    EDIT

    The fix was pushed and released under the new SlickGrid v4.0.1