slickgrid

Slickgrid: Get reference to column changed by columnPicker


I'm using the slickgrid columnPicker to show/hide a specific column

I tried using

columnpicker.onColumnsChanged.subscribe((e, args) => {
   console.log("hello world");
})

but args only gives me all visible columns.

I need to trigger an event when a specific column is being shown.

Is it possible to get a reference to the specific column that was shown/hidden using the columnPicker?


Solution

  • We added the column id 3 years ago, so I can only assume that you are either on a version that is too old OR you're not using the 6pac/SlickGrid fork which is the most active one.

    The latest code is providing the following

    onColumnsChanged.notify({ columnId: columnId, showing: isChecked, allColumns: columns, columns: visibleColumns, grid: _grid });
    

    so you should be able to subscribe to the event and get the columnId

    columnpicker.onColumnsChanged.subscribe((e, args) => {
       console.log("column id changed", args.columnId);
    })
    

    the same is true for the Grid Menu as well

    gridMenu.onColumnsChanged.subscribe((e, args) => {
       console.log("column id changed", args.columnId);
    })
    

    You can see this PR in which I added the columnId to the event. This is available since v2.4.32 of 6pac/SlickGrid fork