dataTable自定义加载内容

时间:2015-11-10 08:22:18

标签: elasticsearch datatables

我通过datatable将查询发布到带有http请求的elasticsearch。并获取json数据作为响应。我需要在jquery datatable中绑定这些数据。

var query="";
    var tableObjects = $("#logTable").DataTable({
        "bProcessing": false,
        "bServerSide": true,
        "sAjaxSource": "http://localhost:9200/webproxylog/_search?source=",
        "aoColumns": [
            {"mDataProp": "clientname" ,"sortable": false },
            {"mDataProp": "clientip"},
            {"mDataProp": "url"},
            {"mDataProp": "category"},
            {"mDataProp": "respsize","sortable": true},
            {"mDataProp": "loggingdate"},
            {"mDataProp": "reqmethod"},
            {"mDataProp": "resultcode"},
            {"mDataProp": "duration"}
        ],
        "fnServerData": function (sSource, aoData, fnCallback){
            var sEcho=aoData[0].value
            query = '{"from":"'+aoData[3].value+'","size":"'+aoData[4].value+'","query":{"match_all":{}},"sort": [{"loggingdate": {"order": "desc"}}]}';
            $.ajax({
                "dataType": "json",
                "contentType": "application/json; charset=utf-8",
                "type": "GET",
                "url": sSource,
                "data": query,
                "success": function(response){
                    debugger
                    var result_ = new Object();
                    result["sEcho"]=sEcho;
                    result["iTotalRecords"]=response.hits.total
                    result["iTotalDisplayRecords"]=response.hits.total
                    result["aaData"]=response['hits']['hits'].map(functio(i){return i['_source']; })});
                    fnCallback(result);
                },
                error: function (xhr, textStatus, error){
                    }
                }});
        },
        "oLanguage": {
            "sLengthMenu": '<select>' +
            '<option value="5">5</option>' +
            '<option value="10">10</option>' +
            '<option value="20">20</option>' +
            '<option value="30">30</option>' +
            '<option value="40">40</option>' +
            '<option value="50">50</option>' +
            '</select> Show'
        },
        "fnCreatedRow": function( nRow, aData, iDataIndex ) {
        },
        "fnDrawCallback": function(){
        },
        "aaSorting": [
            [2, 'asc']
        ],
        "aLengthMenu": [
            [5, 15, 20, -1],
            [5, 15, 20, "All"] // change per page values here
        ],
        "iDisplayLength": 5
    })

我想知道这个目的是否正确。无论如何,有一个错误,我无法获得,成功;响应很好,我为fncallback准备结果数据,但问题是当我点击下一页显示页面中的数据没有改变我检查了查询它没关系,但问题是这里的数据表..

通常我使用与php数据源相同的dt一切正常..我为dt创建自定义回调数据但是有些错误......我该怎么办?

编辑:问题是显示尺寸..但即使它看起来是5,10或50它总是10行页面和数据不会随着分页而改变

0 个答案:

没有答案