4

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

Cornwell
  • 3,304
  • 7
  • 51
  • 84
  • 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? – PostureOfLearning Jul 17 '13 at 23:35
  • Because I could only retrieve the col name. I need getcellmeta for this: http://stackoverflow.com/questions/17721500/custom-renderer-function-not-working-in-handsontable-plugin – Cornwell Jul 18 '13 at 11:24
  • 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. – PostureOfLearning Jul 22 '13 at 00:24

3 Answers3

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
}
Aiden Zhao
  • 564
  • 5
  • 24
Cornwell
  • 3,304
  • 7
  • 51
  • 84
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'.

chris601
  • 53
  • 8
2

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

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97