The event will provide either columnIndex
or columnKey
. In most cases columnKey
is used (index is only when there's no key, which happens when the grid is bound to existing HTML table is auto-generating columns). In your case, you can safely assume you will always get the key, so try something like this to get the index:
{
name: 'Hiding',
columnShowing: function (evt, ui) {
alert(ui.owner.grid.options.columns.indexOf(ui.owner.grid.columnByKey(ui.columnKey)));
// use $.inArray(ui.owner.grid.columnByKey(ui.columnKey),ui.owner.grid.options.columns) instead indexOf() for IE<9 support
alert(ui.columnKey)
}
}
Fiddle: http://jsfiddle.net/damyanpetev/qrsZm/
There are other options to get the column index as well in this forum post that can be used outside event handlers.