数据表列作为标签

时间:2018-08-27 15:09:30

标签: json model-view-controller datatables

比方说,我有一个json返回数据表的数据。搜索基于“ MetroArea”。列为:“ userName”“ LocName”“金额”“ TransDate”“ MetroArea”。在此表中,表的每一行上的“ MetroArea”都是相同的,因此不想显示该列,而是在表上方带有“ Search Results For:[MetroArea]”标签,的情况下,返回的数据可能是“ Denver”。

我有如下所示的(“ #Searchbtn”)。click()函数。它产生了表格,但我不知道如何从第一行获取“ MetroArea”数据,以便给我标签的文本/值。任何建议表示赞赏。非常感谢!

$(document).ready(function () {
    $("#MetroListDiv").hide();

    $("#Searchbtn").click(function () {
        $("#MetroListDiv").show();
        $("#ZipInputDiv").hide();

        var ZipCode = $("#ZipCode").val();

        $("#ProvidersTable").DataTable({

            "ajax": {
                "url": "/Providers/GetProvidersByMetro?ZipCode=" + ZipCode,
                "type": "GET",
                "datatype": "json"
            },
            "columns": [
                { "data": "UserName" },
                { "data": "LocName" },
                {
                    "data": "Amount",
                    'render': $.fn.dataTable.render.number(',', '.', 2, '$' + '  ')

                },
                {
                    "data": "TransDate",
                    'render': function (jsonDate) {
                        var date = new Date(parseInt(jsonDate.substr(6)));
                        var month = date.getMonth() + 1;
                        return month + "/" + date.getDate() + "/" + date.getFullYear();
                    }
                }
        ***here is where "MetroArea" column would be in the script, but I want to capture it from the first row of returned json,
                   OUTSIDE of the "datatable" function, to use as a label for the page***
            ]

        });

    });

})

0 个答案:

没有答案