简体   繁体   中英

Datatable client-side data change/redraw

I set up a datatables that initially gets from server some data and represents it, but then everything is left to the client. Some options are:

serverSide: false,
sAjaxSource: mySource,

My $.fn.DataTable.version is 1.10.2.

Then I need to change, client-side, the aaData under the table because some working on data is performed. I need to update the DT to show the client-altered temporary data without send another request to server (for two reason: prevent useless traffic and because that data is being altered). I am looking for a way to edit the underlying DT databean to edit it, so then calling again

myTable.draw();

on my table I obtain a refresh realtime without sending another get to the server.

The question is, can I access DT data array, and can I edit it?

How is it done if is possible?

EDIT: I need to feed the table the full bean array as it initially took from the server, same format. So individual row/cell add/edit and client-side building functions are not suitable in my case, unless I manually cicle all objects.

SOLUTION

Use the code below:

// Retrieve data
var data = table.ajax.json();

// Modify data
$.each(data.data, function(){
   this[0] = 'John Smith';
});

// Clear table
table.clear();

// Add updated data
table.rows.add(data.data);

// Redraw table
table.draw();

DEMO

See this jsFiddle for code and demonstration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM