createdCell does not work by itself, but createdRow does

createdCell does not work by itself, but createdRow does

adjenksadjenks Posts: 22Questions: 6Answers: 0
edited July 2016 in Free community support

First I tried this but it didn't work. I expected it to concatenate 'test' to the beginning of every cell.

$(document).ready(function() { //when the page has loaded
    var table = $('#example').DataTable({ //create a datatable
        "ajax": {
            "url": "data.txt"
            ,"type": "POST"
            ,"dataSrc": "data" //the data is found in the key "data"
        }
        ,"rowId":3 //selects the column to be a rowID
        ,"createdCell": function (td, cellData, rowData, row, col){
            $(td).html('test'+cellData);
        }
    });

I then tried replacing createdCell by nesting it inside a 'columnDefs' like this and it worked fine.

        ,"columnDefs": [{ //createdCell wasnt working on its own so i had to define it as a default
                "targets": '_all',
                "createdCell": function (td, cellData, rowData, row, col) {
                    $(td).html('test'+cellData);
                }
        }]

What confuses me is that you can use createdRow outside of a "columnDefs" setting and it works fine. Why not createdCell?

Addendum: Even if you do not have a solution, has anyone else experienced this or tried it?

This question has an accepted answers - jump to answer

Answers

  • nico2012nico2012 Posts: 2Questions: 0Answers: 0
    edited October 2016

    No solution, but same problem here. (version 1.10.11 & 1.10.12)

  • allanallan Posts: 64,332Questions: 1Answers: 10,623 Site admin
    Answer ✓

    columns.createdCell is a column property. It needs to be assigned to a column, not at the top level.

    Allan

  • nico2012nico2012 Posts: 2Questions: 0Answers: 0

    Thanks, got it !
    And finally, this solution is more acute

This discussion has been closed.