Get column number from column name
Asked Answered
A

3

5

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

Athletic answered 17/7, 2013 at 20:11 Comment(3)
Can you give more context to your question? Why do you need to get a column number using the name? When and why do you need getCellMeta?Crescantia
Because I could only retrieve the col name. I need getcellmeta for this: #17722000Athletic
Seems to me you are trying to reinvent the wheel a bit here. Handsontable already has some of the functionality you are after. Have a look at my answer to the post you referred to.Crescantia
A
3

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
}
Athletic answered 17/7, 2013 at 21:31 Comment(0)
T
3

This is almost what I required but not quite as I needed the column prop. I couldn't find the answer anywhere so thought I would add this to the thread that helped me.

instead of using 'getColHeader' use 'colToProp'.

Torrietorrin answered 7/4, 2017 at 8:14 Comment(0)
C
2

Use propToCol("Column Name"). This returns the column's index.

Celebrant answered 30/1, 2019 at 12:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.