0
votes

I have an issue where I cannot see the cel values in data table Its a very simple table based on javascript data set

If i remove the columnDefs - I get an error message:

DataTables warning: table id=data_id_N3 - Requested unknown parameter '0' for row 0. For more information about this error, please see http://datatables.net/tn/4

If I add columnDefs then for some reason columnDefs -> defaultContent will takes all default content.

<table width="80%" class="display" id="data_id_N3"></table>

var dataSet = [{"a":"1","b":"2","c":"3"},{"a":"r","b":"t","c":"y"},{"a":"x","b":"y","c":"z"}];


$(document).ready(function() { 
         $('#data_id_N3').DataTable( { 
                    data: dataSet,
                    columns: [

                                { title: "a" } ,      
                                { title: "b" } ,      
                                { title: "c" }
                    ], 
            columnDefs: [{
                targets: '_all',defaultContent: '-'
              }]
                } );

https://jsfiddle.net/bgzdwvkm/1/

1

1 Answers

1
votes

Please use following code.

var dataSet = [{"a":"1","b":"2","c":"3"},{"a":"r","b":"t","c":"y"},{"a":"x","b":"y","c":"z"}];

$(document).ready(function() { 
             $('#data_id_N3').DataTable( { 
                        data: dataSet,
                        columns: [                                    
                                    { title: "a", mDataProp: "a" } ,      
                                    { title: "b", mDataProp: "b"} ,   
                                    { title: "c", mDataProp: "c" }
                        ]
                } );
});

Fiddle