0

I am working on a scheduling project and have run into an issue with finding the column index of a selected cell (so that i may then get the appropriate header for the column). The issue comes into play when a previous cell(or cells) have/has a rowspan. In which case the cell index is off by that amount of cells. I have been at this since yesterday. My current attempt involves using a solution I found in previous posts, and this is this:

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);
         }
     });
    }
    }
});         
})

The problem is that this solution counts the number of rowspanned cells on the entire page. I need a count of the rowspanned cells for only the current clicked cell, and then be able to add that count to index so I can get the proper header. What I have been trying looks like this:

        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);

This information is gathered and then passed to a new form with the selected information used to populate the form. If anyone can help me with this, I would be greatly appreciative!!!

4

0 回答 0