How to Pass geojson array to datatable dyanamically using javascript
The problem is actually the datafile, which is valid JSON but not the structure that datatable requires.
Solution 1 : Change the file to expected structure.
{ "data": [ { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": {}, "geometry": { "type": "LineString", "coordinates": [ [ 40.078125, 57.136239319177434 ], [ 91.7578125, 58.99531118795094 ] ] } } ] } ]}
Solution 2 : Use the dataSrc through which you can modify the ajax response before datatable uses it.
$('#example').dataTable({ "ajax": { "url": "json1.json", "dataSrc": function (json) { var obj = []; obj.data = []; obj.data[0] = json; return obj.data; }, }, "processing": "true", "columns": [ { "data": "type" }, { "data": "features.0.type" }, { "data": "features.0.properties" }, { "data": "features.0.geometry.type" }, { "data": "features.0.geometry.coordinates.0" }, { "data": "features.0.geometry.coordinates.1" } ]});
Here what I've done is created a new object obj.Working fiddle here : https://jsfiddle.net/ourqh9ts/
The problem might be that the GeoJSON is not an array but an object.
Try changing your column definitions with these:
"columns": [ { "data": "type" }, { "data": "features.0.type" }, { "data": "features.0.properties" }, { "data": "features.0.geometry.type" }, { "data": "features.0.geometry.coordinates.0" }, { "data": "features.0.geometry.coordinates.1" }]