我正在为jQuery Javascript库使用DataTables插件。它是一个高度灵活的工具,可以为任何HTML表添加高级交互控件。
为了在html页面上绘制表格,我有以下jquery代码:
$(document).ready(function() {
var columns;
$.ajax({
type: "POST",
url: "./viewController",
data:{ "TableName" : "ViewGridDept",
"Call" : "gridConfiguration"},
dataType:"json",
success: function(coldata){
//columns=data.aoColumns;
//var coldata = eval( '('+data+')' );
alert(coldata.aoColumnsRef);
employeeTable = $("#EmployeeTable").dataTable({
"bJQueryUI" : true,
"sPaginationType" : "full_numbers",
"bFilter": true,
"bInfo": true,
"bServerSide": true,
"sAjaxSource" : "./viewController",
//"aoColumns":coldata.aoColumns ,
"aoColumnDefs":coldata.aoColumnsRef,
//"aoColumnDefs":[{"sTitle":"Department Name","mDataProp":"deptName","aTargets":"[1]"},{"sTitle":"Department ID","mDataProp":"deptId","aTargets":"[0]"}],
"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
} );}
});
}
});
在此代码中我将ajax调用发送到服务器以获取表设置。在呈现表设置之后,第二个ajax调用发送到服务器以获取数据。我以json:
的形式从服务器端获取所有“aoColumnDefs”数据{"aoColumnsRef":[{"aTargets":[1],"mDataProp":"deptName","sTitle":"Department Name","bVisible":true,"bSearchable":true},{"aTargets":[0],"mDataProp":"deptId","sTitle":"Department Id","bVisible":true,"bSearchable":false}]}
我的问题是:
1)此方法是否正确加载来自服务器的设置和数据。
2)他们是从服务器端获取数据和表格设置的任何其他方式。(表格设置意味着列标题,目标,搜索,排序以及与表格相关的所有设置)