1

I am trying to refresh the data from my table, but I am not using ajax and that is why when I try to use table.ajax.reload() it is not working.

It gives me wrong json response since the way I am declaring my table is this:

var table = $('.table').DataTable( {
  "data": global_data,
  "scrollX": true,
  "pagination": false,
  "lengthChange": false,
  "bPaginate": false,
  "language": {
    "url": "http://cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
  },
  "order": [[ 2, "desc" ]],
});

So in another process I update the variable global_data, how to refresh the data?

Thanks

Andrew Lohr
  • 5,380
  • 1
  • 26
  • 38

1 Answers1

1

If you are using datatables you can destroy the data with the following line:

$ ('# mytable'). dataTable (). fnDestroy ();

and fill the table again with the data you want.

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

  "data": global_data,
  "scrollX": true,
  "pagination": false,
  "lengthChange": false,
  "bPaginate": false,
  "language": {
    "url": "http://cdn.datatables.net/plug-ins/1.10.16/i18n/Spanish.json"
  },
  "order": [[ 2, "desc" ]],
});
LMoreno10
  • 73
  • 9
  • IMHO, `fnDestroy` is used by legacy datatable. For DataTable 1.0, [`destroy`](https://datatables.net/reference/option/destroy) will be used. – mmushtaq Nov 01 '17 at 04:56
  • I believe this will raise an error, but if it works for OP it is ok. However, the "correct" or plugin biased way is to set `destroy: true` and then simply recreate the table (with or without new options) see **https://datatables.net/reference/option/destroy** – davidkonrad Nov 01 '17 at 10:35