Having trouble with createdCell

Having trouble with createdCell

karthikaTLkarthikaTL Posts: 4Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Not able to access the column <th> element from this td
Here is the code snippet

columns.push( {
     'title':'<div data-max='+ max +' data-min='+ min +' data-clr='+ clr +'>'+header_name+'</div>',
     "render":{
         display: function(data, type, row){
            ...
         }
     },
     'createdCell' : function (td, cellData, rowData, row, col) {  
         //I have data attributes attached to specific column header 
         //Not able to access the column <th> element from this td

         var alpha = (cellData-min)/(max-min)*(255-20) + 20;
         $(td).css('background-color', clr);
         $(td).css('opacity', alpha);
     }
 });

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    col is the column number - so you would use this to query the header to get the th,

    Colin

  • karthikaTLkarthikaTL Posts: 4Questions: 1Answers: 0

    Table thead & tbody is not populated yet. And $(td).parent() gives tr.
    How to get the div inside thead?

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.