0

我需要一些帮助,我已经查看了数据表 api,但我没有做对。

jQuery代码

$(document).ready(function () {

$('#dblist').on('change', function () {

    var selected = $("select option:selected").text();

    $.ajax({
        url: '/php/connect/searchtablequery.php',
        type: 'POST',
        data: { UserLogin: selected },
        success: function (data) {
            tablefill(data)
        },
        error: function (xhr, status, err) { console.log(xhr, status, err); }
    });

});

function tablefill(data) {

    $('#table_id').dataTable({
        "bProcessing": true,
        "bDestroy": true,
        "sAjaxSource": data,
        "sAjaxDataProp": "data.inner",
        "aoColumns": [
            { "mDataProp": "calldate" },
            { "mDataProp": "clid" },
            { "mDataProp": "src" },
            { "mDataProp": "dst" },
            { "mDataProp": "dcontext"}],
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "sDom": '<"H"Tfr>t<"F"ip>',
        "oTableTools": {
            "sSwfPath": "/DataTables/extras/TableTools/media/swf/copy_csv_xls_pdf.swf",
            "aButtons": [
                "copy", "csv", "xls", "pdf",
                {
                    "sExtends": "collection",
                    "sButtonText": "Save",
                    "aButtons": ["csv", "xls", "pdf"]
                }
            ]
        }
    });
};

});

返回的 JSON 是

{
    "0": {
        "calldate": "2013-08-14 11:41:28",
        "clid": "\"name name\" <1002>",
        "src": "1002",
        "dst": "8834404",
        "dcontext": "from-internal",
        "channel": "SIP\/1002-00000000",
        "dstchannel": "IAX2\/voipms-6749",
        "lastapp": "Dial",
        "lastdata": "IAX2\/voipms\/14798834404,300,",
        "duration": "7",
        "billsec": "0",
        "disposition": "NO ANSWER",
        "amaflags": "3",
        "accountcode": "",
        "uniqueid": "1376498488.1",
        "userfield": "",
        "did": "",
        "recordingfile": "",
        "cnum": "",
        "cnam": "",
        "outbound_cnum": "",
        "outbound_cnam": "",
        "dst_cnam": ""
    },"1": {
        "calldate": "2013-08-14 11:42:55",
        "clid": "\"name name\" <1002>",
        "src": "1002",
        "dst": "9187755592",
        "dcontext": "from-internal",
        "channel": "SIP\/1002-00000001",
        "dstchannel": "IAX2\/voipms-121",
        "lastapp": "Dial",
        "lastdata": "IAX2\/voipms\/19187755592,300,",
        "duration": "494",
        "billsec": "485",
        "disposition": "ANSWERED",
        "amaflags": "3",
        "accountcode": "",
        "uniqueid": "1376498575.3",
        "userfield": "",
        "did": "",
        "recordingfile": "",
        "cnum": "",
        "cnam": "",
        "outbound_cnum": "",
        "outbound_cnam": "",
        "dst_cnam": ""
    },
4

1 回答 1

0

尝试改变:

"sAjaxSource": data,

对此:

"sAjaxSource": '/php/connect/searchtablequery.php',

尝试还添加:

"bServerSide": true,

编辑1:

$(document).ready( function() {
  $('#example').dataTable( {
    "sAjaxSource": "http://www.sprymedia.co.uk/dataTables/json.php"
  } );
} )

参考。http://datatables.net/usage/options

编辑2:

如我的 jsfiddle http://jsfiddle.net/HEDvf/667/所示,您的 JSON 与我的不同。我不知道它是否有影响,但我会尝试改变它。这是我的:

{
    "calldate": "2013-08-14 11:41:28",
    "clid": "\"name name\" <1002>",
    "src": "1002",
    "dst": "8834404",
    "dcontext": "from-internal",
    "channel": "SIP\/1002-00000000",
    "dstchannel": "IAX2\/voipms-6749",
    "lastapp": "Dial",
    "lastdata": "IAX2\/voipms\/14798834404,300,",
    "duration": "7",
    "billsec": "0",
    "disposition": "NO ANSWER",
    "amaflags": "3",
    "accountcode": "",
    "uniqueid": "1376498488.1",
    "userfield": "",
    "did": "",
    "recordingfile": "",
    "cnum": "",
    "cnam": "",
    "outbound_cnum": "",
    "outbound_cnam": "",
    "dst_cnam": ""
},{
    "calldate": "2013-08-14 11:42:55",
    "clid": "\"name name\" <1002>",
    "src": "1002",
    "dst": "9187755592",
    "dcontext": "from-internal",
    "channel": "SIP\/1002-00000001",
    "dstchannel": "IAX2\/voipms-121",
    "lastapp": "Dial",
    "lastdata": "IAX2\/voipms\/19187755592,300,",
    "duration": "494",
    "billsec": "485",
    "disposition": "ANSWERED",
    "amaflags": "3",
    "accountcode": "",
    "uniqueid": "1376498575.3",
    "userfield": "",
    "did": "",
    "recordingfile": "",
    "cnum": "",
    "cnam": "",
    "outbound_cnum": "",
    "outbound_cnam": "",
    "dst_cnam": ""
}

这是你的:

"0":{
    "calldate":"2013-08-14 11:41:28",
    "clid":"\"Ryan Merritt\" <1002>",
    "src":"1002",
    "dst":"8834404",
    "dcontext":"from-internal",
    "channel":"SIP\/1002-00000000",
    "dstchannel":"IAX2\/voipms-6749",
    "lastapp":"Dial",
    "lastdata":"IAX2\/voipms\/14798834404,300,",
    "duration":"7",
    "billsec":"0",
    "disposition":"NO ANSWER",
    "amaflags":"3",
    "accountcode":"",
    "uniqueid":"1376498488.1",
    "userfield":"",
    "did":"",
    "recordingfile":"",
    "cnum":"",
    "cnam":"",
    "outbound_cnum":"",
    "outbound_cnam":"",
    "dst_cnam":""},
"1":{
    "calldate":"2013-08-14 11:42:55",
    "clid":"\"Ryan Merritt\" <1002>",
    "src":"1002",
    "dst":"9187755592",
    "dcontext":"from-internal",
    "channel":"SIP\/1002-00000001",
    "dstchannel":"IAX2\/voipms-121",
    "lastapp":"Dial",
    "lastdata":"IAX2\/voipms\/19187755592,300,",
    "duration":"494",
    "billsec":"485",
    "disposition":"ANSWERED",
    "amaflags":"3",
    "accountcode":"",
    "uniqueid":"1376498575.3",
    "userfield":"",
    "did":"",
    "recordingfile":"",
    "cnum":"",
    "cnam":"",
    "outbound_cnum":"",
    "outbound_cnam":"",
    "dst_cnam":""
},

注意你的“0”和“1”的额外键。我会尝试删除这些并让您的 PHP 文件中的 JSON 看起来更像我的。

于 2013-09-04T18:59:28.510 回答