merging cells breaks the fnGetPosition()

merging cells breaks the fnGetPosition()

mmmgggmmmggg Posts: 5Questions: 0Answers: 0
edited October 2013 in General
Hi,

I have a data table on which I make the first column span 3 rows.
When binding the click event for the cells (td elements) the fnGetPosition() returns correctly only for the first row.
For rows 1 and 2, the column seems to be less than expected (supposedly due to the missing cells that were removed to make room for the rowspan=3).

----------------------
| (0,0) | (0,1) | (0,2) |
| ........|--------------
| ........| (1,0) | (1,1) | <---- I was expecting these would be (1,1) and (1,2)
| ........|--------------
| ........| (2,0) | (2,1) | <---- I was expecting these would be (2,1) and (2,2)
-----------------------

I understand that due to the missing cell in rows 1 and 2, the column index is in fact the one reported, but I was expecting that the cell will maintain the relation with the actula data.

Is this by design?
Is there a way to get the correct column index (in relation to the data) on the click event on such table?

Thank you.

Replies

  • mmmgggmmmggg Posts: 5Questions: 0Answers: 0
    Just found a workarround:

    1. Using the fnCreatedCell for each columnDef, store the actual row&col index in a custom attribute of the TD element:

    [code]
    data.aoColumnDefs[i].fnCreatedCell = function (nTd, sData, oData, iRow, iCol)
    {
    nTd.setAttribute("iRow", iRow.toString());
    nTd.setAttribute("iCol", iCol.toString());
    }
    [/code]

    2. Hook the click event for each cell and get the custom attributes:
    [code]
    $("#tbl tbody td").live('click', function ()
    {
    var iRow = parseInt(this.getAttribute("iRow"));
    var iCol = parseInt(this.getAttribute("iCol"));

    if (iRow != NaN && iCol != NaN)
    {
    var aData = dtAppointments.fnGetData(iRow);
    console.log(aData[iCol]);
    }
    });
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I think a workaround is the best that can be done here - DataTables does not support colspan and rowspan in the table body at the moment.

    Allan
  • mmmgggmmmggg Posts: 5Questions: 0Answers: 0
    Thank you!
    Great plugin!!!
This discussion has been closed.