How to add a new column based on an array

How to add a new column based on an array

rq32rq32 Posts: 2Questions: 1Answers: 0

Hi all,

The table I'm generating is based off of a json file. I would like to add an additional column to the table based on the contents of a separate array. Specifically, I'm trying to make little divs of specific colors cycle throughout the table. How would I go about this?

http://live.datatables.net/yoyunoto/1/edit?html,js,output

Although not exactly the example I posted above, what I have so far is:

var arr= ["#23C67D", "#189BB9", "#9B62B3", "#0D698E", "#93D7E6", "#032861", "#F59231", "#EF5B30"];
var infoTable = $('#pie-chart-table').DataTable({
  "sDom": 't', //lftipr
  "ajax": "/vendor/d3/industryData.json",
  "order": [[ 1, "desc" ]],
  "columns": [
    { "data": "label" },
    { "data": "value" }
  ],
  "ordering": false
});

How would I append a new column?

Thanks in advance.

Answers

  • rq32rq32 Posts: 2Questions: 1Answers: 0

    I ending up hacking it out, using an array with the on(search.dt) function, and having a { "data": null } as my first column.

    var chartSegmentColors= ["#23C67D", "#189BB9", "#9B62B3", "#0D698E", "#93D7E6", "#032861", "#F59231", "#EF5B30"];
    
    infoTable.on( 'search.dt', function () {
            infoTable.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
                cell.innerHTML = "<div style='background-color: "+chartSegmentColors[i]+"'></div>";
            } );
        } ).draw();
    
This discussion has been closed.