从Json填充自定义标题

时间:2016-08-19 05:12:50

标签: json datatable datatables

如何使用hospitallName&amp ;;填充表格的标题? json数据中提供的日期?

**此处添加预期输出**

enter image description here 杰森:

{
"sEcho":2,
"iTotalRecords":243,
"iTotalDisplayRecords":243,
"aaData":[
[
"Mark Zuckerberg",
"USA",
"Feb 14, 1943"
],
[
"John Mathew",
"UK",
"Feb 14, 1943"
],
[
"John Mathew",
"USA",
"Feb 14, 1943"
]
],
"Date":"Aug 01, 2016 - Aug 05, 2016",
"hospitallName":"Apollo Hospital Center"
}

-

在我的服务器端,我这样打电话,

$(document).ready(function() { 
    oTable = $('#report').dataTable({
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "bServerSide": true,
        "bProcessing":true,
        "bFilter":true,
         "oLanguage": {
              "sProcessing": "Please wait..."
         },
        "sAjaxSource": "myDataTableAction.action",
        "aaSorting": [],

    });
    $('td.options span').hide();

    $('<caption/>').html('<h2 style="text-align: center;background-color:#f9b660 !important ; line-height: 45px;">Have to show hosital Name & Date here</h2>').appendTo( '#report' );
});

1 个答案:

答案 0 :(得分:0)

您可以使用ajax代替sAjaxSource,并使用dataSrc回调填充标题。您没有提供布局或标记的任何示例,但如果您将相关标题设为id,则可以执行以下操作:

ajax: {
  url: 'myDataTableAction.action',
  dataSrc: function(json) {
    $('#date_head').text(json.Date)
    $('#hospitalName_head').text(json.hospitallName)
    return json.aaData
 }
}

参见演示 - &gt;的 http://jsfiddle.net/zvqdpeky/