DataTables 1到NaN的NaN

时间:2016-12-28 17:24:01

标签: jquery ajax asp.net-mvc datatables

我正在转换DataTable以使用服务器端处理来减少加载时间,我不能在我的生活中弄清楚为什么页脚不工作。

我认为我正在使用DataTables 1.8.4。

我遇到的大多数答案都提到iTotalDisplayRecordsneeds存在且准确,我相信它是。

所以,如果有人能帮助我,那就太棒了。

jQuery:

if ($(this).hasClass("customerOrderTable")) {
                    $(this).dataTable({
                        "bPaginate": true,
                        "iDisplayLength": 25,
                        "aLengthMenu": [10, 25, 50, 100],
                        "sPaginationType": "full_numbers",
                        "aaSorting": [[s, sdir]],
                        "bServerSide": true,
                        "sAjaxSource": "PathToController?RequestId=" + requestId,
                        "bProcessing": true,
                        "aoColumns": [
                            { "sName": "OrderNumber" },
                            { "sName": "OrderDate" },
                            {
                                "sName": "OrderStatus",
                                "fnRender": function (oObj) 
                                {
                                    return "<span class='badge " + oObj.aData[9] +"'>" + oObj.aData[2] + "</span>";
                                }
                            },
                            { "sName": "DeliveryDetails" },
                            { "sName": "InvoiceDetails" },
                            { "sName": "Value" },
                            { "sName": "Balance" },
                            { "sName": "CustomerType" },
                            {
                                "sName": "Details",
                                "bSearchable": false,
                                "bSortable": false,
                                "fnRender": function (oObj) 
                                {
                                    return "<a class='btn btn-mini' href='PathToController"
                                        + oObj.aData[8] + "'>Details...</a>";
                                }
                            }
                        ]

                    });
                }

控制器:

var customerQuery = (from c in customer.Orders
                                 select c);

            int totalRecords = customerQuery.Count();

            if (!string.IsNullOrEmpty(requestModel.sSearch))
            {
                customerQuery = customerQuery.Where(c => c.OrderNumber.Contains(requestModel.sSearch)
                || c.DeliveryLastname.Contains(requestModel.sSearch)
                || c.DeliveryAddress1.Contains(requestModel.sSearch)
                || c.DeliveryPostcode.Contains(requestModel.sSearch)
                || c.InvoiceDelivery.ToString().Contains(requestModel.sSearch));
            }

            var orderResult = Helpers.Contact.GetCustomerOrdersList(customer, requestModel);

            int totalDisplay = customerQuery.Count();

            return Json(new
            {
                sEcho = int.Parse(requestModel.sEcho),
                iTotalRecords = totalRecords,
                iTotalDisplayRecords = totalDisplay,
                aaData = orderResult,
                //iDisplayStart = requestModel.iDisplayStart,
                //iDisplayLength = requestModel.iDisplayLength
            },
            JsonRequestBehavior.AllowGet);
        }

助手类:

var customerQuery = (from c in entity.Orders
                             select c);

        //I am aware the ordering wont work until this is updated
        customerQuery = customerQuery.OrderBy(c => c.OrderNumber);

        if(!string.IsNullOrEmpty(requestModel.sSearch))
        {
            customerQuery = customerQuery.Where(c => c.OrderNumber.Contains(requestModel.sSearch)
            || c.DeliveryLastname.Contains(requestModel.sSearch)
            || c.DeliveryAddress1.Contains(requestModel.sSearch)
            || c.DeliveryPostcode.Contains(requestModel.sSearch)
            || c.InvoiceDelivery.ToString().Contains(requestModel.sSearch));
        }

        customerQuery = customerQuery.Skip(requestModel.iDisplayStart).Take(requestModel.iDisplayLength);

        ICollection<Business.OrderSummaryModel> ordersList = (from c in customerQuery
                                                              select Business.OrderSummaryModel.MapEntityToSummaryModel(c)).ToList();

        var result = (from x in ordersList
                      select new[] {
                        x.OrderNumber,
                        x.OrderDate.ToString(),
                        x.OrderStatus,
                        x.DeliveryName + "/" + x.DeliveryPostcode,
                        x.BillingName + "/" + x.BillingPostcode,
                        x.Currency + x.InvoiceGrandTotal.ToString("#,##0.00"),
                        x.Currency + x.OutstandingBalance.ToString("#,##0.00"),
                        x.CustomerType,
                        x.Order_ID.ToString(),
                        x.StatusClass

                    });

        return result;

返回的JSON会显示正确的值:

{
"sEcho":"1",
"iTotalRecords":25,
"iTotalDisplayRecords":25,
"data":
[
["001",
    "26/06/2013 14:03:27",
    "Dispatched",
    "TheCustomer1",
    "Address1",
    "Value1",
    "Type1",
    "ID1",
    "ExtraData1"
],
[
    etc
],

0 个答案:

没有答案