【问题标题】:Kendo Grid not Paging data剑道网格不分页数据
【发布时间】:2014-05-15 09:48:12
【问题描述】:

我将 Kendo Grid 用于我的 ASP.NET MVC 应用程序,该应用程序使用 ajax 绑定进行读取。 它将数据绑定到第一页,但不显示网格的页数。 它显示 (| >|)。


Index.cshtml

        @(Html.Kendo().Grid<Club.Areas.Admin.Models.Users>()
            .Name("grid")                
            .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("List1", "Home"))
                .PageSize(5)                                                
            )                
            .Columns(columns =>
            {
                columns.Bound(p => p.Id).Filterable(false).Width(100);
                columns.Bound(p => p.NickName).Width(100);
                columns.Bound(p => p.UserVisitLastDate).Format("{0:MM/dd/yyyy}").Width(140);                    
                columns.Bound(p => p.Mobile).Width(100);
            })
            .Pageable()                
            .Sortable()                
            .HtmlAttributes(new { style = "width:500px;height:430px;" })                
    )


HomeController

    public class HomeController : Controller
{        
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult List1([DataSourceRequest]DataSourceRequest request)
    {
        List<Users> U = new List<Users>();
        for (int i = 0; i < 100; i++)
        {
            U.Add(new Users
            {
                NickName = "Mehdi",
                Company = "Taral",
                Email = "M.Farokhtabar@Gmail.com",
                Family = "FT",
                HomeAddress = "Isfahan",
                HomePhone = "03112332940",
                IsActive = true,
                Mobile = "09131025834",
                Name = "Mehdi",
                UserCreateDate = DateTime.Now,
                UserVisitLastDate = DateTime.Now,
                WebSite = "",
                WorkAddress = "Mehdi",
                PostalCode = "1234567890",
                Id = i,
                WorkPhone = "03117726250"
            });
        }
        DataSourceResult result = U.ToDataSourceResult(request);            
        return Json(result,JsonRequestBehavior.AllowGet);            
    }
}

【问题讨论】:

  • 可以发截图吗?

标签: kendo-ui grid kendo-grid kendo-asp.net-mvc


【解决方案1】:

您必须设置数据源的serverPaging: true 并确保来自服务器的响应具有包含项目数量的总计字段。

【讨论】:

    【解决方案2】:

    我的答案与 MVC 方法并不完全相关,我已将它与 WebAPI 控制器一起使用。数据源应如下所示:

    var sampleDataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: svcSampleUrl,
                contentType: "application/json; charset=utf-8",
                type: "POST",
                dataType: "json"
            },
            parameterMap: function (options) {
                model.Take = options.take;
                model.Skip = options.skip;
                model.Sort = options.sort;
                model.Filter = options.filter;
                return kendo.stringify(model);
            }
        },
        schema: {
            data: "sampleDTOList",
            total: "totalItems",
            model: {
                fields: {
                    ID: { type: "number" },
                    Label: { type: "string" },
                    Description: { type: "string" }
                }
            }
        },
        serverPaging: true,
        serverFiltering: true,
        serverSorting: true
    });
    

    架构中的总属性是获取记录总数并计算要显示的页面数的位置。在您的情况下,您正在接收第一页的数据,并且网格不知道有多少数据来计算需要的总页数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-26
      • 2023-03-18
      • 1970-01-01
      • 2014-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多