Asp.net mvc 4 无法按照剑道网格中的页面大小显示记录

Asp.net mvc 4 无法按照剑道网格中的页面大小显示记录,asp.net-mvc-4,kendo-grid,Asp.net Mvc 4,Kendo Grid,我想在剑道网格中执行过滤、排序和记录编号,但它不起作用 这是我的查看页面: <script> $(document).ready(function () { $("#categories-grid").kendoGrid({ dataSource: { type: "json",

我想在剑道网格中执行过滤、排序和记录编号,但它不起作用

这是我的查看页面:

<script>
                $(document).ready(function () {
                    $("#categories-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("categoriesList", "Admin"))",
                                    type: "POST",
                                    dataType: "json",
                                    data: '',
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors"
                            },
                            error: function(e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            pageSize: 2,
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            pageSizes: [10,20,30]
                        },
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [{
                            field: "CategoryName",
                            title: "CategoryName",
                            width: 100
                        }, {
                            field: "CategoryId",
                            title: "Edit",
                            width: 100,
                            template: '<a href="/Admin/ViewCategoryDetails?categoryId=#=CategoryId#&categoryName=#=CategoryName#">Edit</a>'
                        }]
                    });

                });

            </script>
这是我的分类模型:

 public class CategoryModel
    {
        public int CategoryId { get; set; }
        public string CategoryName { get; set; }
        public int frequency { get; set; }

        public virtual ICollection<SubcategoryModel> subCategory { get; set; }
    }
我有12个类别。当我设置每页dat为2时,它显示所有记录


任何人都可以告诉我代码中的问题是什么以及如何执行排序和过滤吗?

不要使用自定义DataSourceRequest类,而是使用KendoGridMvcRequest类,该类正确映射分页、排序和过滤

也可作为


请参阅此演示。

更改您的模式以充当函数

schema: {
   data: function(response) {
    return response.Data ; 
   }
   total: function(response) {
     return response.Total; 
   }
},
并可传呼至

pageable: {
 refresh: true,
 pageSizes: [2,10,20,30]
},
并且不要在代码中看到DataSourceRequest的使用,因为您没有从读取中发送页面大小。发送DataSourceRequest对象并仅返回DataSourceRequest中指定的内容。在这种情况下,只有两条记录

transport: {
            read: function (options) {

               var commandOBJ=[{
                    Page: 1, // Once the first two item is loaded and you click for the next page you will have the page in "options" (should be like options.page)
                    PageSize:2 
                }];

                $.ajax({
                    url:"@Html.Raw(Url.Action("categoriesList", "Admin"))",
                    data: { command: bookmarkID },
                    dataType: "json",
                    cache: false,
                    success: function (result) {
                        options.success(result);
                    },
                    error: function (result) {
                        options.error(result);
                    }
                });
            }
        }

现在,从动作分类列表中检查命令并相应地发送数据。你的阅读动作可以是GET而不是POST。希望这有帮助

我没有使用剑道网格的dll。我使用的是剑道的css和js。你能编辑我的代码并为我提供解决方案吗?当使用剑道Binderex项目时,你不需要任何剑道dll,只有JS和CSS版本的免费编辑在使用KendoGridBinderExyaa时排序和过滤才能正常工作,但我不想使用它。你使用过吗?我使用KendoGridBinderEx是因为我开发了它。请看一下github上的源代码,看看它是如何使用的。你可以写下你的整个脚本bcz一半你已经写了一半dwon,所以我不明白,还可以发布你的控制器逻辑。plz plz plz plz plz plz。我对mvc非常陌生,所以请随控制器一起发送你的整个脚本。亲爱的朋友,你只需要替换模式,使用脚本和categoriesList操作进行分页和传输与MVC无关。它只是简单的编程逻辑。我在这里指导你。您的操作逻辑应该是,查看命令参数pagesize和page并返回相应的结果。就像第一次加载一样,pagesize是2,page是1,所以只返回两条记录。完成分页后,JS dataSource read将发送页面和页面大小。然后从您的操作发送第二组数据,如果第2页和大小为2。yaa我理解bt,我的控制器逻辑将是相同的,因为u r说方法fire将是get而不是post/。yaa我理解,但我的控制器逻辑将是相同的?那么我使用的post方法dat呢?我需要更改dat吗?您的控制器逻辑应该更改,正如我在前面的评论中所解释的。是的,将其更改为GET方法,因为我的代码数据源read执行GET Ajax调用。
pageable: {
 refresh: true,
 pageSizes: [2,10,20,30]
},
transport: {
            read: function (options) {

               var commandOBJ=[{
                    Page: 1, // Once the first two item is loaded and you click for the next page you will have the page in "options" (should be like options.page)
                    PageSize:2 
                }];

                $.ajax({
                    url:"@Html.Raw(Url.Action("categoriesList", "Admin"))",
                    data: { command: bookmarkID },
                    dataType: "json",
                    cache: false,
                    success: function (result) {
                        options.success(result);
                    },
                    error: function (result) {
                        options.error(result);
                    }
                });
            }
        }