最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Datatable client-side data changeredraw - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited Aug 28, 2015 at 14:03 Nillus asked Aug 28, 2015 at 12:14 NillusNillus 1,1991 gold badge14 silver badges34 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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.

发布评论

评论列表(0)

  1. 暂无评论