简体   繁体   English

数据表客户端数据更改/重绘

[英]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. 我的$ .fn.DataTable.version是1.10.2。

Then I need to change, client-side, the aaData under the table because some working on data is performed. 然后我需要在客户端更改表下的aaData,因为执行了一些数据处理工作。 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). 我需要更新DT以显示客户端更改的临时数据,而不向服务器发送另一个请求(出于两个原因:防止无用流量并且因为该数据正在被更改)。 I am looking for a way to edit the underlying DT databean to edit it, so then calling again 我正在寻找一种方法来编辑底层的DT数据库来编辑它,然后再次调用

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? 问题是,我可以访问DT数据阵列吗?我可以编辑它吗?

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. 编辑:我需要为表格提供最初从服务器获取的完整bean数组,格式相同。 So individual row/cell add/edit and client-side building functions are not suitable in my case, unless I manually cicle all objects. 所以单独的行/单元格添加/编辑和客户端构建函数在我的情况下是不合适的,除非我手动cicle所有对象。

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 DEMO

See this jsFiddle for code and demonstration. 有关代码和演示,请参阅此jsFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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