【问题标题】:Integrating Kendo Grid with Coldfusion将 Kendo Grid 与 Coldfusion 集成
【发布时间】:2014-12-19 17:12:47
【问题描述】:

我们希望从当前的网格 (JQWidgets) 切换到 KendoUI 网格,我正在研究概念验证。我们最大的需求是服务器端分页/排序/过滤,这就是我遇到问题的地方。

我们现有的网格是基于 XML 的,所以我创建了一个 Kendo 网格来做同样的事情:

$(document).ready(function(){
    var xmlDataRemote = new kendo.data.DataSource({
        transport: {
            read: { url: "/KendoDashboard/KendoController.cfc?method=getGrid" }
        }, 
        pageSize: 20, 
        serverPaging: true, 
        serverSorting: true,
        serverFiltering: true,
        schema: {
            type: "xml",
            data: "/Items/Item",
            total: "/Items/Item/TotalRows",
            model: {
                id: "ID",
                fields: {
                    Name: { field: "Name/text()", type: "string" },
                    Status: { field: "Status/text()", type: "string" },
                    Type: { field: "Type/text()", type: "string" }
                }
            }
        }
    });

    var grid = $("#grid").kendoGrid({
        dataSource: xmlDataRemote,
        pageable: true,
        sortable: true, 
        filterable: true,
        columns: [
            { title: "Name", field: "Name" },
            { title: "Status", field: "Status" },
            { title: "Type", field: "Type" }    
        ]
    });
});

示例 XML:

<Items>           
    <Item>
        <ID>1</ID>
        <Name>First Item Name</Name>
        <Status>Active</Status>
        <Type>Online</Type>   
    </Item>           
    <Item>
        <ID>2</ID>
        <Name>Second Item Name</Name>
        <Status>Inactive</Status>
        <Type>External</Type>
    </Item>
    <TotalRows>22</TotalRows>
</Items>

我的分页问题:在数据源上设置的总数似乎不起作用。网格页脚有“没有要显示的项目”而不是“22 个项目中的 1-20 个”并且没有分页选项。我也不确定从网格传递的“take”和“skip”参数(见下文)的用途。

我的排序/过滤问题:传递的排序和过滤参数是一些格式奇怪的字符串:

/KendoDashboard/KendoController.cfc?method=getCoursesGrid&take=20&skip=0&page=1&pageSize=20&sort%5B0%5D%5Bfield%5D=Name&sort%5B0%5D%5Bdir%5D=desc&filter%5Blogic%5D=and&filter%5Bfilters%5D%5B0%5D%5Bfield%5D=Name&filter%5Bfilters%5D%5B0%5D%5Boperator%5D=eq&filter%5Bfilters%5D%5B0%5D%5Bvalue%5D=test

如果我在 Firebug 中查看,参数列出为:

filter[filters][0][field]   Name
filter[filters][0][operator]    eq
filter[filters][0][value]   test
filter[logic]   and
method  getCoursesGrid
page    1
pageSize    20
skip    0
sort[0][dir]    desc
sort[0][field]  Name
take    20

设置一个名称为“filter”和字符串类型的 cfargument,然后将其转储出去,只会返回零 (0)。当然,Coldfusion 不会采用“filter [filters]”的参数名称,所以我对如何进行有点茫然。

【问题讨论】:

  • 关于总数问题,schema 对象中total 的值是否不是"/Items/TotalRows", 而不是"/Items/Item/TotalRows",
  • 我认为 take 和 skip 参数在使用 LINQ 时很有用。当我使用带有 SQL 数据库后端的 Kendo 网格时,我刚刚使用了 pageSize 和 page 参数来实现服务器端分页。 pageSize 和 page 可以在 MySQL 查询的 LIMIT 子句中使用。
  • @Michael - 你是对的,我已经纠正了它,但仍然没有运气。感谢LIMIT的提示,我去看看。

标签: coldfusion kendo-grid


【解决方案1】:

您可以将总计设置为

total: function(response) {
  return response.Items.TotalRows;
}

如果有问题,请查看 response 变量

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2018-03-08
    相关资源
    最近更新 更多