Search code examples
handsontable

Get column number from column name


Is there any method to get the column number from the column name?

I can only retrieve the column name, and I need the column number for getCellMeta.

Thanks


Solution

  • Made this function that solved my problem:

    function GetColFromName(name)
    {
        var n_cols  =   $editorTableContainer.handsontable('countCols');
        var i       =   1;     
    
        for (i=1; i<=n_cols; i++)
        {
            if (name.toLowerCase() == $editorTableContainer.handsontable('getColHeader', i).toLowerCase()) {
                return i;
            }
        }
        return -1; //return -1 if nothing can be found
    }