so i am doing dashboard project,and got a vendor table using dataTables,and fetch data to table from API,the API will give json data,but i kinda confuse,because it's my first time fill the table with api data,usually i fetch the data from local database,and because there's many reference with sql fetching
here's the example API Json data :
{"produkList":[{"product_code":"XXXXX","ticket":"UD","numbers":"1200","price": 20,"verification":true},{"produk_code":"XXXXXX","ticket":"UD","numbers":"4000","price":120,"verification":false}]}
datatables js (view) :
table = $('#table').DataTable({
"processing": true, //Feature control the processing indicator.
"serverSide": true, //Feature control DataTables' server-side processing mode.
"order": [], //Initial no order.
// Load data for the table's content from an Ajax source
"ajax": {
"url": "<?php echo site_url('dashboard/ajax_list')?>",
"type": "POST"
},
//Set column definition initialisation properties.
"columnDefs": [
{
"targets": [ -1 ], //last column
"orderable": false, //set not orderable
},
],
});
and the controller (Dashboard.php)
public function ajax_list()
{
$curl = curl_init("http://example.com/dashboard/APIget.php");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS);
$result = curl_exec($curl);
curl_close($curl);
echo json_encode($result);
}
and for the models,i still haven't got idea,because i only know to fetch from local database,and i know that i can get the data from API without serverside processing,but the result is that the bigger the data,the site will taking to long to load,so anyone know how ?