我刚刚开始使用 datatables 1.9 jquery 插件,但面临从服务器端获取数据表配置。我的数据表代码是:
$.ajax({
type: "POST",
url: "./viewController",
data:{ "TableName" : "ViewGridDept",
"Call" : "gridConfiguration"},
dataType:"json",
success: function(data){
//columns=data.aoColumns;
var coldata = eval( '('+data+')' );
alert(coldata.aoColumns);
employeeTable = $("#EmployeeTable").dataTable({
"bJQueryUI" : true,
"sPaginationType" : "full_numbers",
"bFilter": true,
"bInfo": true,
"bServerSide": true,
"sAjaxSource" : "./viewController",
"aoColumns":coldata.aoColumns ,
"aoColumnDefs":coldata.aoColumnsRef,
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name" : "TableName", "value" : "ViewGridDept" },
{ "name" : "Call", "value" : "Data" } );
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );}
我来自服务器端的 json 是
{"aoColumns":[{"mDataProp":"deptName","sTitle":"Department Name"},{"mDataProp":"deptId","sTitle":"Department Id"}],"aoColumnsRef":[{"aTarget":["2"]},{"aTarget":["1"]}]}
但我的数据表没有加载数据。我的问题是如何将嵌套的 json 用于数据表"aoColumns":coldata.aoColumns ,
"aoColumnDefs":coldata.aoColumnsRef,