在AJAX调用之后,我的数据表不会刷新

时间:2017-11-09 00:28:27

标签: datatables

您好我已经设置了我的数据表。我能够显示页面加载的数据。但是,当我单击下一页时,将调用服务器端并返回数据,但数据表不会刷新。谁能告诉我发生了什么事?

$(document).ready(function () {
   //get Data Tables Query
   buildDataTables();
});


function buildDataTables() {
    if (!$.fn.DataTable.isDataTable('#locationTable')) {
        $('#locationTable').DataTable({
            "bServerSide": true,
            "sAjaxSource": '/Home/GetDataTablesQuery',
            paging: true,
            "iDisplayLength": 10,
            "aoColumns": [
                { "mData": "Address1", "name": "Address 1" },
                { "mData": "City", "name": "City" },
                { "mData": "Size", "name": "Approx SF" },
                { "mData": "StoreNumber", "name": "Store #" },
            ]
        });
    }

如何刷新分页上的数据表数据?

2 个答案:

答案 0 :(得分:0)

我知道问题是什么。我总是在响应中将sEcho设置为10。我们需要将DataTable发送的值传递给服务器。

 [AllowAnonymous]
        public AdvancedJsonResult GetDataTablesQuery(LocationsFilter locationFilter)
        {
            List<LocationInfo> locationInfos = new List<LocationInfo>();
            int totalRecords = 0;

            locationFilter.CurrentPage = (locationFilter.iDisplayStart/locationFilter.iDisplayLength) + 1;

            ////Default Page Number to 1 if Zero
            //if (locationFilter.CurrentPage == 0)
            //{
            //    locationFilter.CurrentPage = 1;
            //}

            //Default Page Size
            locationFilter.PageSize = locationFilter.iDisplayLength;

            //Get Records
            locationInfos = _LocationInfoLogic.Get(locationFilter, out totalRecords);
            var dataTablesResponse = new { aaData = locationInfos.ToArray(), iTotalRecords = totalRecords, iTotalDisplayRecords = totalRecords, sEcho = locationFilter.sEcho };
            return new AdvancedJsonResult { Data = dataTablesResponse };
        }

答案 1 :(得分:0)

最简单的方法是在ajax成功调用时编写以下代码 Traceback (most recent call last): TypeError: mylemmatize() takes exactly 1 argument (0 given) 127.0.0.1 - - [16/Mar/2018 14:31:51] "POST /glcoding HTTP/1.1" 500 -

如果您想将响应保留在同一页面上 $("#datatble").DataTable().ajax.reload();