2

我正在为 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)他们是从服务器端获取数据和表格设置的任何其他方式吗?(表格设置意味着列标题、目标、搜索、排序和所有与表格相关的设置)

4

0 回答 0