2013-07-17 76 views
3

是否有任何方法从列名获取列号?从列名获取列号

我只能检索列名,我需要getCellMeta的列号。

感谢

+0

你可以给你的问题更多的上下文吗?为什么你需要使用名称获得列号?何时以及为什么你需要getCellMeta? – PostureOfLearning

+0

因为我只能检索col名称。我需要getcellmeta这个:http://stackoverflow.com/questions/17721500/custom-renderer-function-not-working-in-handsontable-plugin – Cornwell

+0

对我来说,你似乎试图在这里重新发明轮子。 Handsontable已经具备了你之后的一些功能。看看我提到的帖子的回答。 – PostureOfLearning

回答

2

提出这一功能解决了我的问题:

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 
} 
1

这几乎是我需要的,但并不像我所需要的列道具。我无法在任何地方找到答案,因此我想将它添加到帮助我的线程中。

而不是使用'getColHeader'使用'colToProp'。