我想通过ajax调用将我的数据表的内容发布到服务器。
FWIW,这是表格的样子......即,
收集数据表"数据"提交,我使用的功能:
.rows().data()
实际陈述如下:
var page0griddata = JSON.stringify(page0grid.rows().data());
page0griddata的内容看起来像这样(我已将其截断,因为"元数据"部分太长了)...即,
{"0":{"id":0,"fieldAStrg":"XXX0","fieldBStrg":"YYY0"},"1":{"id":1,"fieldAStrg":"XXX1","fieldBStrg":"YYY1"},"context":[{"oFeatures":{"bAutoWidth":true,"bDeferRender":false,"bFilter":false,"bInfo":false,"bLengthChange":false,"bPaginate":false,"bProcessing":false,"bServerSide":false,"bSort":false,"bSortMulti":true,"bSortClasses":true,"bStateSave":null},"oScroll":{"bCollapse":true,"iBarWidth":17,"sX":"","sXInner":"","sY":600},"oLanguage":{"fnInfoCallback":null,"oAria":{"sSortAscending":": activate to sort column ascending","sSortDescending":": activate to sort column descending","_hungarianMap":{"sortAscending":"sSortAscending","sortDescending":"sSortDescending"}},"oPaginate":{"sFirst":"First","sLast":"Last","sNext":"Next","sPrevious":"Previous","_hungarianMap":{"first":"sFirst","last":"sLast","next":"sNext","previous":"sPrevious"}},"sEmptyTable":"No data available in table","sInfo":"Showing _START_ to _END_ of _TOTAL_ entries","sInfoEmpty":...(REST IS TRUNCATED)...
以下部分(我正在处理的实际数据)......是我真正需要的......即,
{"0":{"id":0,"fieldAStrg":"XXX0","fieldBStrg":"YYY0"},"1":{"id":1,"fieldAStrg":"XXX1","fieldBStrg":"YYY1"},
是否有DataTables api方法只返回这些数据? (上述)?
FYI - 如果数据表定义有问题,下面是表格定义......即,
var page0grid = jq('#page0grid').DataTable({
"ajax": $contextPath + "/page0/testGridList",
"columns": [
{"title": "ID", "data": "id", "visible": false },
{"title": "Field A", "data": "fieldAStrg" },
{"title": "Field B", "data": "fieldBStrg" }
],
"columnDefs": [{
"targets": 3,
"data": null,
"defaultContent": "<button class='edit'>Edit</button>"
}],
"info": false,
"searching": false,
"bPaginate": false,
"scrollY": 600,
"bLengthChange": false,
"bScrollCollapse": true,
"autoWidth": true,
"order": [[ 0, 'desc' ]],
"bSort": false
});
感谢您的帮助!
答案 0 :(得分:1)
显然我的问题的答案是使用名为:&#34; toArray()&#34; ...
的Datatables API函数例如,
var page0griddata = JSON.stringify(page0grid.rows().data().toArray());
(特别感谢Allen - 来自dataTables.net/forums!)