[转]KendoUI系列:Grid

本文转自:http://www.cnblogs.com/libingql/p/3774879.html

1、基本使用

<div id="grid"></div>
<link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.common.min.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.default.min.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/kendo/2014.1.318/jquery.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/kendo/2014.1.318/kendo.web.min.js")" type="text/javascript"></script>

<script type="text/javascript">
    $(function () {
        $("#grid").kendoGrid({
            dataSource: {
                transport: {
                    dataType: "json",
                    read: "/Province/GetProvinceList"
                },
                pageSize: 10,
            },
            pageable: {
                refresh: true,
                pageSizes: true,
                buttonCount: 5
            },
            columns: [{
                field: "ProvinceID",
                title: "省份ID",
                width: 200
            }, {
                field: "ProvinceNo",
                title: "省份编号"
            }, {
                field: "ProvinceName",
                title: "省份名称"
            }]
        });
    });
</script>

  效果预览:

  说明:pageSizes设置可选择每页显示的条数,buttonCount设置最多显示的页数,超出时则显示...。以上实现方式第一次从服务端加载出全部的数据,Kendo UI Grid进行客户端分页。

  2、绑定本地数据

<div id="grid"></div>

<script type="text/javascript">
    $(function () {
        var provinces = [{ "ProvinceID": 1, "ProvinceNo": "110000", "ProvinceName": "北京市" }, { "ProvinceID": 2, "ProvinceNo": "120000", "ProvinceName": "天津市" }, { "ProvinceID": 3, "ProvinceNo": "130000", "ProvinceName": "河北省" }, { "ProvinceID": 4, "ProvinceNo": "140000", "ProvinceName": "山西省" }, { "ProvinceID": 5, "ProvinceNo": "150000", "ProvinceName": "内蒙古" }, { "ProvinceID": 6, "ProvinceNo": "210000", "ProvinceName": "辽宁省" }, { "ProvinceID": 7, "ProvinceNo": "220000", "ProvinceName": "吉林省" }, { "ProvinceID": 8, "ProvinceNo": "230000", "ProvinceName": "黑龙江" }, { "ProvinceID": 9, "ProvinceNo": "310000", "ProvinceName": "上海市" }, { "ProvinceID": 10, "ProvinceNo": "320000", "ProvinceName": "江苏省" }, { "ProvinceID": 11, "ProvinceNo": "330000", "ProvinceName": "浙江省" }, { "ProvinceID": 12, "ProvinceNo": "340000", "ProvinceName": "安徽省" }, { "ProvinceID": 13, "ProvinceNo": "350000", "ProvinceName": "福建省" }, { "ProvinceID": 14, "ProvinceNo": "360000", "ProvinceName": "江西省" }, { "ProvinceID": 15, "ProvinceNo": "370000", "ProvinceName": "山东省" }, { "ProvinceID": 16, "ProvinceNo": "410000", "ProvinceName": "河南省" }, { "ProvinceID": 17, "ProvinceNo": "420000", "ProvinceName": "湖北省" }, { "ProvinceID": 18, "ProvinceNo": "430000", "ProvinceName": "湖南省" }, { "ProvinceID": 19, "ProvinceNo": "440000", "ProvinceName": "广东省" }, { "ProvinceID": 20, "ProvinceNo": "450000", "ProvinceName": "广西" }, { "ProvinceID": 21, "ProvinceNo": "460000", "ProvinceName": "海南省" }, { "ProvinceID": 22, "ProvinceNo": "500000", "ProvinceName": "重庆市" }, { "ProvinceID": 23, "ProvinceNo": "510000", "ProvinceName": "四川省" }, { "ProvinceID": 24, "ProvinceNo": "520000", "ProvinceName": "贵州省" }, { "ProvinceID": 25, "ProvinceNo": "530000", "ProvinceName": "云南省" }, { "ProvinceID": 26, "ProvinceNo": "540000", "ProvinceName": "西藏" }, { "ProvinceID": 27, "ProvinceNo": "610000", "ProvinceName": "陕西省" }, { "ProvinceID": 28, "ProvinceNo": "620000", "ProvinceName": "甘肃省" }, { "ProvinceID": 29, "ProvinceNo": "630000", "ProvinceName": "青海省" }, { "ProvinceID": 30, "ProvinceNo": "640000", "ProvinceName": "宁夏" }, { "ProvinceID": 31, "ProvinceNo": "650000", "ProvinceName": "新疆" }, { "ProvinceID": 32, "ProvinceNo": "710000", "ProvinceName": "台湾省" }, { "ProvinceID": 33, "ProvinceNo": "810000", "ProvinceName": "香港" }, { "ProvinceID": 34, "ProvinceNo": "820000", "ProvinceName": "澳门" }];

        $("#grid").kendoGrid({
            dataSource: {
                data: provinces,
                schema: {
                    model: {
                        fields: {
                            ProvinceID: { type: "number" },
                            ProvinceNo: { type: "string" },
                            ProvinceName: { type: "string" }
                        }
                    }
                },
                pageSize: 10
            },
            pageable: {
                input: true,
                numeric: false,
                messages: {
                    display: "{0} - {1} 共 {2} 条数据",
                    empty: "没有数据",
                    page: "页",
                    of: "/ {0}",
                    itemsPerPage: "条每页",
                    first: "第一页",
                    previous: "前一页",
                    next: "下一页",
                    last: "最后一页",
                    refresh: "刷新"
                }
            },
            columns: [{
                field: "ProvinceID",
                title: "省份ID"
            }, {
                field: "ProvinceNo",
                title: "省份编号"
            }, {
                field: "ProvinceName",
                title: "省份名称"
            }]
        });
    });
</script>

  3、绑定远程数据

<div id="grid"></div>

<script type="text/javascript">
    $(function () {
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: {
                    type: "post",
                    url: "/Province/GetProvincePagedList",
                    dataType: "json",
                    contentType: "application/json"
                },
                parameterMap: function (options, operation) {
                    if (operation == "read") {
                        var parameter = {
                            page: options.page,
                            pageSize: options.pageSize
                        };
                        return kendo.stringify(parameter);
                    }
                }
            },
            batch: true,
            pageSize: 10,
            schema: {
                data: function (d) {
                    return d.data;
                },
                total: function (d) {
                    return d.total;
                }
            },
            serverPaging: true
        });

        $("#grid").kendoGrid({
            dataSource: dataSource,
            pageable: {
                pageSizes: true,
                buttonCount: 5,
                messages: {
                    display: "显示{0}-{1}条,共{2}条",
                    empty: "没有数据",
                    page: "页",
                    of: "/ {0}",
                    itemsPerPage: "条/页",
                    first: "第一页",
                    previous: "前一页",
                    next: "下一页",
                    last: "最后一页",
                    refresh: "刷新"
                }
            },
            columns: [{
                field: "ProvinceID",
                title: "省份ID",
                width: 150
            }, {
                field: "ProvinceNo",
                title: "省份编号"
            }, {
                field: "ProvinceName",
                title: "省份名称"
            }]
        });
    });
</script>

public ActionResult GetProvincePagedList(int page, int pageSize)
{
    ctx.Configuration.ProxyCreationEnabled = false;

    return Json(new { data = ctx.Provinces.OrderBy(p => p.ProvinceID).Skip((page - 1) * pageSize).Take(pageSize), total = ctx.Provinces.Count() }, JsonRequestBehavior.AllowGet);
}

时间: 2024-10-24 14:49:05

[转]KendoUI系列:Grid的相关文章

KendoUI系列:Grid

1.基本使用 <div id="grid"></div> <link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.common.min.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Cont

KendoUI系列:AutoComplete

1.基本使用 <link href="@Url.Content("~/C ontent/kendo/2014.1.318/kendo.common.min.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.default.min.css&

中文版kendoUI API — Grid(一)

1.altRowTemplate 类型:Function | String 说明:提供表格行的交替模板,默认grid表格为每一个数据元素提供一个tr 注意:模板中最外层的html元素必须是<tr>,这个<tr>必须有一个uid属性,并设置为#= uid #,grid使用uid属性判定绑定行的元素. Example: 通过Function方式提供模板 1 <div id="grid"></div> 2 <script id="

KendoUI系列:TreeView

1.加载本地数据 <link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.common.min.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.default.min.css

kendoui treeview grid spreadsheet

treeview 傻子方式获取id <!DOCTYPE html> <html> <head> <title>API</title> <meta charset="utf-8"> <link href="../content/shared/styles/examples-offline.css" rel="stylesheet"> <link href=&q

KendoUI关于Grid页面刷新赋值(不修改数据库)

1.Grid页面某个字段修改赋值(不用刷新) var row = GG.data("kendoGrid").select(); var data = GG.data("kendoGrid").dataItem(row); data.set("IP", "1212"); 2.Grid刷新 var grid = $("#SearchGrid").data("kendoGrid"); grid

KendoUI系列:MultiSelect

1.基本使用 1>.创建Input <link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.common.min.css")" rel="stylesheet" type="text/css" /> <link href="@Url.Content("~/Content/kendo/2014.1.318/kendo.def

KendoUI系列:ComboBox

http://wenku.baidu.com/link?url=ns89CE_ulk-dKfgi2Z3PnVJtx2hZpvEXHj5EAsDnUbZEdOd5jNhLRpfnA779uFdedrz2wlqZTsQD8GwYqxCiXRM4vE614WoPiJs3wRzont7&qq-pf-to=pcqq.c2c 局域网共享文件夹权限设置 1.打开"我的电脑"快捷图标,在开启的主界面中依次打开"工具→文件夹选项" 2.在打开的对话框中单击"查看&q

[React]全自动数据表格组件——BodeGrid

表格是在后台管理系统中用的最频繁的组件之一,相关的功能有数据的新增和编辑.查询.排序.分页.自定义显示以及一些操作按钮.我们逐一深入进行探讨以及介绍我的设计思路: 新增和编辑 想想我们最开始写新增编辑页面是怎么做的,是不是一个页面一个页面的写,然后要么表单提交要么Ajax提交.后台有无数个新增和编辑的视图页,现在想想真是恐怖啊,看着都累.后面接触到kendoui的grid组件,看到只需要配置列的属性以及保存的地址就能自动完成新增和编辑功能,着实让我兴奋了一把.然而不幸的是我几乎找遍了react所