如何在涉及rowpans时查找单元格索引

时间:2013-08-21 18:24:32

标签: php jquery

我正在研究一个调度项目,并且遇到了查找所选单元格的列索引的问题(这样我就可以获得该列的相应标题)。当前一个单元格(或单元格)具有/具有行跨时,该问题就会发挥作用。在这种情况下,细胞指数偏离该细胞量。我从昨天起就一直在这。我目前的尝试涉及使用我在之前的帖子中找到的解决方案,这就是:

parentTr.find('>td, >th').each(function(i,o) {
    if ( this == reference ) 
    {
    cellNum = i;

    var counter = columnNum;

    while ( counter-- ) 
    {
    $(this).closest('tr').next().find('>td,>th').each(function(i,o) 
    {
        if ( cellNum == i ) 
        {
            $(this).addClass('rowspan-affected');
            $(this).attr('colNum', columnNum);
         }
     });
    }
    }
});         
})

问题是此解决方案计算整个页面上的行跨单元格数。我只需要对当前单击的单元格计数行数单元格,然后能够将该计数添加到索引中,这样我就可以得到正确的标题。我一直在尝试的是这样的:

        var $this = $(this);
        //get the row header contents
        var row = $this.parent('tr').contents('th:eq(0)').html();
        //trying this
        var colCount = $(this).prevAll().find('td').parent('tr').attr('rowspan');
        alert (colCount);
        //used to get the cell index
        var rowIndex = $(this).parent().index('.main tbody tr');
        var tdIndex = $(this).index('.main tbody tr:eq('+rowIndex+') td');
        //alert ("tdindex " + (tdIndex+1));
        var headerObj = $(this).parents('.main').find('th').eq(tdIndex+1);
        //strip whitespace before passing
        var toPass =   $.trim(headerObj.text());
        //toPass = $.trim(toPass)
        //alert (toPass);

收集此信息,然后将其传递到新表单,其中包含用于填充表单的所选信息。 如果有人能帮助我,我会非常感激!!!

0 个答案:

没有答案