Getting Datatables and Sparklines to play nice together? Getting Datatables and Sparklines to play nice together? flask flask

Getting Datatables and Sparklines to play nice together?


Got it. This always happen every time I post a stackoverflow question, but I think i'd be stuck for a few days if I didn't post so..

Anyways, after reading the docs for a few hours -- The aoColumnDefs is a selector that can select an entire row in the table (if it's already created in the HTML) and that was wrong in my code above.. The aTargets is the parameter that you pass in the index of the column and the mRender is the call back function that you call right before it spits out whatever to the screen (it can modify the data beforehand for that specific col)

The diff is that I sent the code to the HTML using the columns and then I targeted the whole col to attatch the tags on and sent them over

Posting my code in hopes this saves someone time

$('#table_id').DataTable({                   data:{{ data|safe}},                    columns: [                        {data: 'table_name'},                        {data: 'col_name'},                        {data: 'rule'},                        {data: 'current'},                        {data: 'min'},                        {data: 'max'},                        {data: 'median'},                        {data: 'mean'},                        {data: 'data'},                    ],                    "aoColumnDefs": [                    {                        "aTargets": [8],                        "mRender": function (data, type, full) {                             // since data is an array of values [1,2,3,4]                            return '<span class="spark">' + data + '</span>'                        }                    }                ],               "drawCallback": (oSettings) => {                   console.log('callback');                   console.log($('.spark:not(:has(canvas))'))                  $('.spark:not(:has(canvas))').sparkline('html', {                      type: 'line',                      minSpotColor: 'red',                      maxSpotColor: 'green',                      spotColor: false                  });              }               });