How to parse an array as a data source for URL button

How to parse an array as a data source for URL button

aoediaaoedia Posts: 2Questions: 1Answers: 0

I have an array called datatablearray as such :

var datatablearray = [item1, item2, item3]

and I want the items in the array to be iterativelly displayed in the table (item1 to go into row 1, item2 into row 2, etc.).

I wrote the code as such :


var table = $('#example').DataTable( { "data": dattablearray', "scrollX": true, "scrollCollapse": true, "columnDefs": [ { "targets": 0, "data" : datatablearray, "render" : function (url, type, full){ return '<a role = "button" class="btn btn-secondary" href="/'+ datatablearray +'" title="link" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="width: 100%; opacity: 0.7;filter: alpha(opacity=50); color: #FFFF00; background: #424141">'+ datatablearray +' </a>' }} ],

However when I run that, it displays the whole array [item1, item2, item3] into the rows where I only want the one item. And if I do a datatablearray[0], it displays only the first item for all of the instances and rows.

Answers

  • aoediaaoedia Posts: 2Questions: 1Answers: 0

    So I solved it - the way to do it was to make the data in the columnDefs equal to null, and to call data inside the return statement in render

This discussion has been closed.