将数据表数据导出到ajaxSource

Export Datatable data to ajaxSource

本文关键字:ajaxSource 数据表 数据      更新时间:2023-09-26

我有一个表,使用datatables标记(http://dandelion.github.io/datatables/)它生成一个典型的dataTable。

<datatables:table id="myTableId" data="${persons}" row="person">
   <datatables:column title="Id" property="id" />
   <datatables:column title="FirstName" property="firstName" />
   <datatables:column title="LastName" property="lastName" />
   <datatables:column title="City" property="address.town.name" />
   <datatables:column title="Mail">
      <a href="mailto:${person.mail}">${person.mail}</a>
   </datatables:column>
</datatables:table>

我想把所有的数据都作为Ajax souce生成,我想是之类的

var sAjaxSource=JSON.parse(localStorage.getItem('myTableId'));

要使用典型的Ajax格式在变量中获取存储数据,请执行以下操作:

{
aaData: [
  hash1: [[1, "value1"], [2, "value2"]],
  hash2: [[3, "value3"], [4, "value4"]],
  hash3: [[5, "value5"], [6, "value6"]]
        ]
}

但这行不通。这可能吗?知道吗?感谢

完成!

function array2dToJson(a, p, nl) {
              var i, j, s = '{"' + p + '":[';
              nl = nl || '';
              for (i = 0; i < a.length; ++i) {
                s += nl + array1dToJson(a[i]);
                if (i < a.length - 1) {
                  s += ',';
                }
              }
              s += nl + ']}';
              return s;
            }
var table = $('#myTableId').dataTable({'bRetrieve': true})
var data = table.fnGetData();
array2dToJson(data, 'data', ''n');