行没有出现在DataTable中

时间:2016-05-09 10:41:21

标签: datatables

我的视图中有一个DataTable,如下所示:

 <table id="tblProviders" style="font-size:x-small;width:100%; border: 1px solid black;">
                <caption>Assigned Providers</caption>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Phone</th>
                        <th>Role</th>
                        <th>Remove</th>
                    </tr>
                </thead>
            </table>

分配数据:

 $("#tblProviders").dataTable({
        bProcessing: true,
        sAjaxSource: '@Url.Action("GetProvidersById")?id=' + $("#txtid").val(),
        bJQueryUI: true,
        sProcessing: "<img src='~/Images/spinner.gif' />",
        dom: 'T<"clear">rtip',
        "pageLength": 5,
        bAutoWidth: false,
        "oLanguage": {
            sEmptyTable: "There are no Providers at this time",
            sZeroRecords: "There are no Providers at this time"
        },
        "aoColumns": [
            { "sWidth": "1%", sClass: "smallFonts" },
            { "sWidth": "15%", sClass: "smallFonts" },
            { "sWidth": "15%", sClass: "smallFonts" },
            { "sWidth": "15%", sClass: "smallFonts" },
            { "sWidth": "15%", sClass: "smallfonts" },
            {
                "sWidth": "15%", sClass: "centerbutton", "sName": "UserId", "mRender": function (data, type, row) {

                    return "<button type='button' class='displaybutton' id='" + row[0] + "' onclick=RemoveProvider(this);return false; >Remove</button>";
                }
            }
        ],
        tableTools: {
            "sSwfPath": "../../Scripts/swf/copy_csv_xls_pdf.swf",
            "aButtons": [

            ]

        }
    });
    $("#tblProviders").dataTable().fnSetColumnVis(0, false);
    otab = $("#tblProviders").dataTable();
    otab.fnSort([[1, 'asc']]);

我知道我收到了正确的JSON数据:

 [HttpGet]
    public ActionResult GetProvidersId(string id)
    {
        return Json(new
        {
            aaData = Repository.GetProvidersById(id).Select(x => new String[] {
                x.ID.ToString(),
                x.FirstName + " " + x.LastName,
                x.Email,
                x.Phone,
                x.Role,
            })
        }, JsonRequestBehavior.AllowGet);
    }

但是没有一行显示出来。我在这做错了什么?事实上,如果我通过在删除点放置调试点来调试表的加载,我会看到数据,但它从不显示。

1 个答案:

答案 0 :(得分:1)

不幸的是,问题是由于我使用加载到主视图中的字母搜索引起的。一旦过滤开始并显示部分视图,过滤在该局部视图中继续,有效地显示无结果。我还有另外一个关于这个问题的问题,目前还没有答案。