javascript Kendo Grid 中的寻呼机错误(Nan-Nan of 1 items)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23941065/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 01:51:44  来源:igfitidea点击:

Pager error in Kendo Grid(Nan-Nan of 1 items)

javascriptjquerykendo-grid

提问by Rohini

I am trying to create a Kendo grid with a list of student details. On click of the add button, the pager shows "Nan-Nan of 1 items".

我正在尝试创建一个包含学生详细信息列表的剑道网格。单击添加按钮后,寻呼机显示“Nan-Nan of 1 items”。

@(Html.Kendo().Grid<Student.Models.StudentDetails>()
            .Name("StudentDetailsGrid")
             .Pageable()
                 .HtmlAttributes(new { id="StudentDetailsGrid"})
            .Columns(col =>
                {col.Bound(a => a.FirstName).Title("Name");

                    col.Bound(a => a.LastName).Hidden()
                    col.Bound(a => a.StudentID).Hidden();
                    col.Command(a => { a.Destroy(); a.Edit(); }).Title("");
                }
            )
            .ToolBar(toolbar => toolbar.Create().Text("Add").HtmlAttributes(new {@id="btnCreateStudent"}))
            .Editable(editable => editable.Mode(GridEditMode.InLine))
                .Scrollable(scrol => scrol.Enabled(true))

            .DataSource(source => source
                .Ajax()
                .PageSize(5)

                .Model(a =>
                {
                    a.Id(b => b.StudentID);


                })

             .Read(read => read.Action()
             .Create(create => create.Action())
             .Destroy(destroy => destroy.Action())
             .Update(update => update.Action())


           ).Events(even => even.Save("SaveDetails").Edit("ChangeNoOfStudent").DataBound("StudentValidate")))

`

`

on Document.ready function :

在 Document.ready 函数上:

$(document).ready(function () {
        $.ajax({
                url: '../Student/GetStudentDetails?StudentId=' + Data.StudentId,
                type: 'POST',
                contentType: 'application/json',
                dataType: 'json',
                success: function (data) {

                    if (data.length > 0) {


                        var studentdetail = new kendo.data.DataSource({
                            data: data,
                            pageSize: 5

                        });
                        $("#StudentDetailsGrid").data("kendoGrid").setDataSource(studentdetail);

                    }

I have added the page size, but I can still see the "Nan-Nan of 1 items".

我已经添加了页面大小,但我仍然可以看到“Nan-Nan of 1 items”。

Can you please help?

你能帮忙吗?

回答by freedeveloper

You need to define the pageSize in the grid data source. Not in the success function.

您需要在网格数据源中定义 pageSize。不在成功函数中。

In your case you only need to include in your data source the following:

在您的情况下,您只需要在数据源中包含以下内容:

 $.ajax({
                url: '../Student/GetStudentDetails?StudentId=' + Data.StudentId,
                type: 'POST',
                contentType: 'application/json',
                dataType: 'json',
                pageSize: 10,
                success: function (data) {...

I hope this helps. More information at: Sudarsan Dash'blogs

我希望这有帮助。更多信息请访问:Sudarsan Dash'blogs

回答by Kishore

I made it work like below: specifying the pagesize inside the datasource fixed my problem (Nan-Nan of 1 items)

我使它的工作如下:在数据源中指定页面大小解决了我的问题(1 个项目的南南)

< script type = "text/javascript" >

  $(document).ready(function() {

    var modelData = @Html.Raw(Json.Encode(Model));

    $("#grid").kendoGrid({

      reorderable: true,
      pageable: {
        input: true,
        numeric: false
      },
      scrollable: true,
      sortable: true,
      dataSource: {
        data: modelData,
        pageSize: 10 // specifying the pagesize inside the datasource fixed my problem (Nan-Nan of 1 items)
      },
      columns: [{
        field: "fieldparameter",
        title: "titleparameter",
        filterable: true,
        sortable: true
      }]
    });
  }); < /script>

回答by Majase

This is what you need to resolve the issue. Works like a dream!

这是您解决问题所需要的。像梦一样工作!

<script>
    $(document).ready(function () {

        $("#grid").kendoGrid({

            dataSource: {
                pageSize: 10
            },

        });
    });
</script>

回答by Gurusinghe

Add pageSize:5 inside of dataSource:{ } as,

在 dataSource:{ } 中添加 pageSize:5 为,

         dataSource: {
            pageSize: 5
         }

if you put pageSize: 5 outside of dataSource:{ } you will get that error "Nan-Nan"

如果你把 pageSize: 5 放在 dataSource:{ } 之外,你会得到那个错误“Nan-Nan”

回答by alexdannylow

For some reason, simply adding pageSize to my datasource was not working for me.

出于某种原因,简单地将 pageSize 添加到我的数据源对我不起作用。

I solved this problem by setting my initial grid page to 1, and my pageSize is also defined in my datasource:

我通过将初始网格页面设置为 1 解决了这个问题,并且我的 pageSize 也在我的数据源中定义:

                    var grid = $("#grid").data("kendoGrid");
                    var dataSource = new kendo.data.DataSource({ data: response.data });
                    grid.setDataSource(dataSource);
                    grid.dataSource.page(1); // need so that Nan - Nan is not the starting page.
                    grid.dataSource.read();

回答by kunal

Remove .PageSize(5) from @(Html.Kendo().Grid() Add pageSize: 5 in var studentdetail = new kendo.data.DataSource({

从@(Html.Kendo().Grid() 中删除 .PageSize(5) 添加 pageSize: 5 in var studentdetail = new kendo.data.DataSource({