DataTable上的服务器端处理

时间:2014-04-10 04:39:46

标签: php

我在服务器端处理时使用DataTable。此表显示表中没有数据

var DataTableApp = $('#DataTableApp').dataTable({
            "sAjaxSource": "php/getAppDetails.php",
            "bRetrieve":true,
            "bDestroy":true,
            "bServerSide": true,
            "fnServerParams": function ( aoData ) {
                var imei_apps = document.getElementById('imei').value;
                console.log(imei_apps);
                aoData.push( { "name": "imei", "value": imei_apps } );
            },

            "aoColumns": [{
                "mData": "appName",             
            }, {
                "mData": "appId",
            }, {
                "mData": "versionInstalled"
            }, {
                "mData": "appSize",
            }, {
                "mData":"dataSize",
            },{
                "mData": "appType",
            },{
                "mData":"installedLocation",
            },{
                "mData": "appType",
            }],
        });

该代码中的错误是什么?我找不到解决方案

1 个答案:

答案 0 :(得分:1)

尝试构建与此类似的响应:

{"sEcho": $sEcho, "iTotalRecords": $total, "iTotalDisplayRecords": $filtered,
 "aaData": [
     [$row1_col1, $row1_col2, $row1_col3],
     [$row2_col1, $row2_col2, $row2_col3]
  ]}

在PHP中它看起来像这样:

$json = new stdClass;
$json->aaData = array();
$json->aaData[] = array($row1_col1, $row1_col2, $row1_col3);
$json->aaData[] = array($row2_col1, $row2_col2, $row2_col3);

$encoded_json = json_encode($json);