Skip to content Skip to sidebar Skip to footer

Getting Datatables And Sparklines To Play Nice Together?

Im currently trying to get Datatables and the Sparklines packages to work together kind of like below: (This stuff is all written in R however) I realize my issue is similar to th

Solution 1:

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
                  });
              }
               });

Post a Comment for "Getting Datatables And Sparklines To Play Nice Together?"