Error in "DataTables highlighting example"

Error in "DataTables highlighting example"

adsoodadsood Posts: 10Questions: 0Answers: 0
edited September 2011 in Bug reports
Hi there,
I was looking for a highlight row axample and noticed that "DataTables highlighting example" ( http://datatables.net/release-datatables/examples/api/highlight.html ) displays wrong column as highlighted.

It actually highlights the column next after the one where mouse cursor is located.
If the cursor is on the last column, datatable highlights the first column.

I am not sure if there is a bug in the core or the example has it, but anyway want to bring your attention to it.

Replies

  • allanallan Posts: 63,386Questions: 1Answers: 10,449 Site admin
    lol - thanks for that! The bug is in the line:

    [code]
    $('td:nth-child('+(iCol+1)+')', nTrs)
    [/code]

    that +1 has no business being there...! I'll get this fixed - thanks for the heads up!

    Allan
  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    was there a change in jQuery? I don't remember which, but some of their functions were 1-indexed (for uniformity with the DOM library, I think), while most were 0-indexed. this might have been one of them and perhaps they changed it recently.
  • allanallan Posts: 63,386Questions: 1Answers: 10,449 Site admin
    That would make sense - I'm sure I wouldn't have committed in the column highlighting doing some obviously wrong. I wonder if nth-child has been slightly changed in one of the newer versions - which looks at it looks like a good change to me!

    Allan
  • allanallan Posts: 63,386Questions: 1Answers: 10,449 Site admin
    Nope - it was me... The example was ropey... I had:

    [code]
    $('td').index(this);
    [/code]

    should have been:

    [code]
    $('td', this.parentNode).index(this);
    [/code]

    Doh! Its a wonder it was only off by one column... Example fixed and commit just about to go to github. Weirdly it worked on my local server, but not datatables.net - can't explain that. However, both happy now!

    Thanks for spotting that!

    Allan
This discussion has been closed.