【问题标题】:Setting Json data from webservice in datatables在数据表中设置来自 web 服务的 Json 数据
【发布时间】:2018-07-01 01:27:16
【问题描述】:

我必须将从 web 服务返回的数据设置为数据表 HTML 表。给出了代码。我已尝试设置列,但这不起作用,显示“表中没有可用数据”。

HTML

     <table id="example" cellspacing="0" width="100">
                    <thead class="scrollmenu">
                        <tr>
                            <th>Sr.#</th>
                            <th>Reference</th>
                            <th>Type</th>
                            <th>Value Date</th>
                            <th>Amount</th>
                            <th>Transaction Type</th>
                            <th>Sender Bic</th>
                            <th>Receiver Bic</th>
                            <th>Receiver Account</th>
                            <th>Sender Account</th>
                            <th>Sender</th>
                            <th>Receiver</th>
                            <th>Payer's Participant</th>
                            <th>Beneficiary Participant</th>
                            <th>Creation Date</th>
                        </tr>
                    </thead>


                    <tbody>
                    </tbody>
                </table>

JavaScript

var datefrom = $('#dateFrom').val();
    var dateto = $('#dateTo').val();
    $.ajax({
        type: "POST",
        url: "/DashBoard/fetchDataDetails?flag="+flag+"&from=" + datefrom + "&" + "to=" + dateto,
         contentType: "application/json; charset=utf-8",
        success: function (data) {
            debugger;
            if (data.length > 0) {
                debugger;
                var abc = data;
                $('#example').DataTable({
                    "paging": true,
                    "ordering": true,
                    "info": true,
                    "columns": [
                        { "data": "system_reference_no" },
                        { "data": "mt_type" },
                        { "data": "system_refdate" },
                        { "data": "system_refamount" },
                        { "data": "TransType_Code" },
                        { "data": "sender" },
                        { "data": "receiver" },
                        { "data": "receiver_account" },
                        { "data": "sender_account" },
                        { "data": "sender_bic" },
                        { "data": "receiver_bic" },
                        { "data": "sender_bank" },
                        { "data": "receiver_bank" },
                        { "data": "creation_date" },
                    ]
                });

            }
            //  processingGif(false);
        },
        error: function (data) {
            // processingGif(false);
        }



    });

但这不起作用。我尝试了不同的选择,但无法让它发挥作用。需要帮助。

【问题讨论】:

  • 您需要调试向DashBoard/fetchDataDetails发出的AJAX请求

标签: jquery json api web-services datatables


【解决方案1】:

您需要使用data 选项将数据传递给DataTable。

$('#example').DataTable({
   // ... skipped ...
   "data": data 
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 2016-04-02
    相关资源
    最近更新 更多