Answers for "jquery datatable get data array"

1

jquery datatable get data array

var table = $('#example').DataTable();
 
var plainArray = table
    .data()
    .toArray();
Posted by: Guest on October-14-2021
0

jquery datatable ajax get data

DataTables Example Using an Ajax Callback

The DataTables ajax option, here is a common way to retrieve
dynamic data from a source, for loading into a table.

$('#example').dataTable( {
  "ajax": {
    "url": "https://myurl.goeshere.com/mydata",
    "type": "POST",
    "dataSrc": "my_data"
  }
} );

However, you can also use a function with the DataTables ajax option, 
instead of an object. Here is an example:

$(document).ready(function() {

  var table = $('#demo').DataTable( {

    ajax: function (data, callback, settings) {
      $.ajax({
        url: "http://localhost:7000/ajax-employee-objects",
      }).then ( function( json, textStatus, jqXHR ) {
		json["data"] = json["row_objects"];
		delete json["row_objects"];
		//console.log(textStatus); // "success"
		//console.log(json.extra_data.foo); // "bar"
        callback(json);
      });
    },
    columns: [
      { data: "name" },
      { data: "position" },
      { data: "office" },
      { data: "extn" },
      { data: "start_date" },
      { data: "salary" }
    ]
  });

} );

Github NathanNoSudo
Posted by: Guest on June-18-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language