Kendo UI Grid结合Window完善Custom事件

今天来总结一下Grid控件的使用,在数据源绑定到Grid上后,我们肯定希望能对其进行编辑和删除,这里记录一下自己对于编辑的心得使用;

在asp.net mvc环境下做的

首先我们定义一个需要绑定数据实体;

    public class VehicleLocation
    {
        [DisplayName("车牌号")]
        public string CarNum { get; set; }
        [DisplayName("状态")]
        public int GPSOnLineStatus { get; set; }
        [DisplayName("经度")]
        [DataType("Number")]
        public double Longitude { get; set; }
        [DisplayName("纬度")]
        [DataType("Number")]
        public double Latitude { get; set; }
        [DisplayName("速度")]
        public decimal Speed { get; set; }
        [DisplayName("方向")]
        public decimal Angle { get; set; }
        [DisplayName("定位时间")]
        [DataType("DateTime")]
        public DateTime GPSTime { get; set; }
        [DisplayName("具体位置")]
        public string Address { get; set; }
        [DisplayName("方向")]
        public string AngleMsg
        {
            get
            {
                string angle = "0";
                if (this.Angle > 22 && this.Angle <= 68)
                {
                    angle = "东北";
                }
                else if (this.Angle > 68 && this.Angle <= 112)
                {
                    angle = "东";
                }
                else if (this.Angle > 112 && this.Angle <= 158)
                {
                    angle = "东南";
                }
                else if (this.Angle > 158 && this.Angle <= 202)
                {
                    angle = "南";
                }
                else if (this.Angle > 202 && this.Angle <= 248)
                {
                    angle = "西南";
                }
                else if (this.Angle > 248 && this.Angle <= 292)
                {
                    angle = "西";
                }
                else if (this.Angle > 292 && this.Angle <= 338)
                {
                    angle = "西北";
                }
                else
                {
                    angle = "北";
                }
                return angle;
            }
        }
    }

该对象作为显示在Grid上的实体;

下面介绍一下定义的Grid格式,看看最后一列,我们此处不使用它本身自带的command.Edit()方法来实现编辑按钮,因为那样的整个编辑界面就会固定化,按照实体对象属性个数逐个列出;

通过自定义方法,同样可以对编辑界面的模版进行设计;

@(Html.Kendo().Grid<VehicleLocation>()
    .Name("vehicleGrid")
    .Columns(columns =>
    {
        columns.Bound(p => p.CarNum).Width(100);
        columns.Bound(p => p.Longitude).Width(100);
        columns.Bound(p => p.Latitude).Width(100);
        columns.Bound(p => p.Speed).Width(100);
        columns.Bound(p => p.AngleMsg).Width(100);
        columns.Bound(p => p.GPSTime).Width(100);
        columns.Bound(p => p.GPSOnLineStatus).Width(100);
        columns.Command(command =>
        {
            command.Custom("edit").Text("编辑")
                .HtmlAttributes(new { @class = "k-icon k-edit" })
                .Click("editVehicleLocation");
        }).Width(172);
    })
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:430px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(30)
        .Model(model => model.Id(p => p.CarNum))
        .Read(read => read.Action("BindingVechilesLocation", "Home"))
    )
)
然后,定义个弹出框'

@(Html.Kendo().Window().Name("Details")
    .Title("信息修改")
    .Visible(false)
    .Modal(true)
    .Draggable(true)
    .Width(300)
)
同时定义每个编辑按钮的click脚本事件;

<script>
    var windowObject;

    $(document).ready(function () {
        windowObject = $("#Details").data("kendoWindow");
    });

    function editVehicleLocation(e) {
        e.preventDefault();

        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));

        windowObject.refresh({
            url: "/Home/Test_Edit?carnum=" + dataItem.CarNum
        });
        windowObject.center().open();
    }
</script>

解释一下,点击"编辑"后会自动跳转到一个编辑页面/Home/Test_Edit,参数通过Request.Params["carnum"]获取;

在Controller中定义Test_Edit的控制器

        public ActionResult Test_Edit()
        {
            string carnum = Request.Params["carnum"];
            //从记录中获取符合条件的对象
            VehicleLocation vlocation = new VehicleLocation();
            return View(vlocation);
        }
        [HttpPost]
        public ActionResult Test_Edit(VehicleLocation vlocation)
        {
            //此处做编辑操作
            return View();
        }

上述主要介绍了Grid的自定义弹出window窗口的方法;

图一,数据列表


图二,点"编辑"效果


至于样式这些都是可以再继续调整的,这里就没有进行过多处理


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
JSP(JavaServer Pages)是一种动态网页开发技术,它允许在HTML页面中插入Java代码和JSP标签。JSP技术可以让我们将Java代码和HTML页面进行分离,使得开发人员可以更加专注于网站的业务逻辑。在JSP中,我们可以使用Java的各种API,包括JDBC API、Servlet API等,从而实现动态网页的生成和数据交互。 Kendo UI是一套基于jQuery的Web应用程序UI框架,它提供了大量的UI组件和工具,如图表、表格、表单、日历、导航等,用于构建现代化的Web应用程序。Kendo UI通过提供丰富的UI组件和易用的API,简化了Web应用程序的开发过程,帮助开发人员快速构建出高质量的Web应用程序。 Element UI是一套基于Vue.js的UI框架,它提供了一系列的组件和工具,如表格、表单、弹窗、消息提示等,用于快速构建现代化的Web应用程序。Element UI通过提供丰富的组件和简洁易用的API,使得Web应用程序的开发变得更加高效和便捷。 关于Kendo UI与Element UI之间的比较,它们都是非常优秀的UI框架,在不同的场景下都有自己的优势。Kendo UI提供了更多的组件和工具,以及更多针对企业级应用程序的特性,而Element UI则更注重于简洁易用和响应式设计。如果您正在使用Vue.js作为您的前端框架,那么Element UI可能更适合您。如果您需要更多的组件和工具,并且正在开发一个大型的企业级应用程序,则Kendo UI可能更适合您。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值