columnDefs.data

columnDefs.data

ThomDThomD Posts: 334Questions: 11Answers: 43
edited September 2015 in DataTables 1.10

I'm working on a column that is a calculated value, using the columnDef.data option. When I had the column defined like this:

{  data: null, title:"Outlier" }

my columnsDef was ignored. I had to change the column declaration to this

    {  title:"Outlier" }    ,   

to get it to work. Is that expected?

Also, is there a difference between using columnDefs.data()


columnDefs: [ { targets: [ -6 ], data: function (row, type, val, meta) { do some crazy business logic return myresult; } ]

and doing the same thing (with a function) in the columns.data option?

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Your first two code lines above have no "target". A columnDefs definition requires a target.

  • ThomDThomD Posts: 334Questions: 11Answers: 43
    edited September 2015

    Sorry, the first two lines are from the columns option of the initial dataTable load.


    $('#example').DataTable( { data: myDataSet, columns: [ { title: "Outlier" }, ... ] } );
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    We'd really need a link to a test page showing the issue please.

    Allan

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    This isn't an issue per se because I found a way to make it work (Don't declare 'data' in two palces), it's an observation.

    Since you can define the data for a column in either the columns option of the dataTables() call or in the columnsDef() area, does it matter where this is done?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You can do either, and it can actually be useful to do both, but the value defined in the columns array will always "win". There can be only one value in the end (to paraphrase an old film :-) ).

    Allan

This discussion has been closed.