0

我有一个 KendoGrid,我将数据源设置为事件读取:

public virtual JsonResult ContactsListRead([DataSourceRequest] DataSourceRequest request)
{
   return Json(ContactsModel.ContactsService.Get().ToDataSourceResult(request));
}

ContactsModel.ContactsService.Get() 方法,返回一个 IQueryable:

 var qContactsOpen = from x in promo.Contacts
                                            where x.type == type && (x.closure_id == 0 || x.closure_id == null)
                                            orderby x.id descending
                                            select new ContactsGrid
                                            {
                                                Id = x.id,
                                                DescriptionA = x.description_A,
                                                Address = x.address,
                                                PhoneA = x.phone_A,
                                                CategoryDescription = x.Categories.description,
                                                Location = x.location,
                                                Subject = x.subject,
                                                Note = x.ContactsActivities.Where(o=>o.promotion_id == promo.id).OrderByDescending(o => o.date).Select(o => o.note).FirstOrDefault() ?? "",
                                            };

                        return (qContactsOpen.AsQueryable());

在网格上我有分页(20),所以,我希望无论查询中的记录数是多少,ContactsListRead,都需要一点时间,而不是大量的记录需要很多时间......

我忘记了什么?

4

3 回答 3

0

确保在 DataSource 中设置serverPaging为。true

于 2013-10-09T17:15:06.143 回答
0

也许 DataSourceRequest 是空的。确保你的页面中包含了 kendo.aspnetmvc.min.js。

于 2013-10-10T06:44:03.337 回答
0

我解决了在读取事件中添加海关过滤器/排序/分页,并在网格中设置 ServerOperation(true) .. 它工作得很好

    public ActionResult ContactsListRead([DataSourceRequest] DataSourceRequest request)
    {
        IEnumerable<ContactsModel.ContactsGrid> query = ContactsModel.ContactsService.Get();

        int count = ContactsModel.ContactsService.GetCount();

        query = AjaxCustomBindingExtensions.ApplyOrdersFiltering(query, request.Filters, out count, count);

        query = AjaxCustomBindingExtensions.ApplyOrdersSorting(query, request.Groups, request.Sorts);

        query = AjaxCustomBindingExtensions.ApplyOrdersPaging(query, request.Page, request.PageSize);

        IEnumerable data = AjaxCustomBindingExtensions.ApplyOrdersGrouping(query, request.Groups);

        var result = new DataSourceResult()
        {
            Data = data,
            Total = count
        };

        return Json(result,JsonRequestBehavior.AllowGet);
    }
于 2013-10-11T07:25:19.460 回答