Kendo Grid不分页数据

时间:2014-05-15 09:48:13

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

我使用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);            
    }
}

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我的回答与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
});

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