Kendo Grid 布尔型数据显示 日期格式化 筛选 排序

前台:

var url = '@Url.Action("Grid", "Day")' + "?departmentCode=" + node.DepartmentSystemCode + "&employeeTypeId=" + $("#EmployeeTypeId").val();

var dataSource = new kendo.data.DataSource({
            serverPaging: true,
            pageSize: 20,
            serverSorting: true,
            //serverFiltering: true,
            transport: {
                read: {
                    //type: 'post',
                    dataType: 'jsonp',
                    url: url
                },
                parameterMap: function (options) {
                    var result = {
                        pageSize: options.pageSize,
                        page: options.page,
                    };
                    if (options.sort) {
                        for (var i = 0; i < options.sort.length; i++) {
                            result["sort[" + i + "].Field"] = options.sort[i].field;
                            result["sort[" + i + "].Dir"] = options.sort[i].dir;
                        }
                    }
                    return result;
                }
            }, schema: {
                model: {
                    id: "Id",
                    fields: {
                        EmployeeNo: { type: "string" },
                        EmployeeName: { type: "string" },
                        Department: { type: "string" },
                        DutyDate: { type: "DateTime" },
                        ShiftName: { type: "string" },
                        BeginTime: { type: "DateTime" },
                        EndTime: { type: "DateTime" },
                        CardBeginTime: { type: "DateTime" },
                        CardEndTime: { type: "DateTime" },
                        WorkHours: { type: "float" },
                        FactWorkHours: { type: "float" },
                        LateTimes: { type: "float" },
                        EarlyTimes: { type: "float" },
                        AbsentCount: { type: "number" },
                        AbsentTimes: { type: "float" },
                        OverCount: { type: "number" },
                        OverTimes: { type: "float" },
                        LeaveCount: { type: "number" },
                        LeaveTimes: { type: "float" },
                        OutCount: { type: "number" },
                        OutTimes: { type: "float" },
                        IsDone: { type: "float" },
                    }
                },
                data: "data",
                total: "total"
            }
        });
        $("#grid").kendoGrid({
            scrollable: true,
            sortable: true,
            filterable: true,
            pageable: true,
            dataSource: dataSource,
            selectable: "multiple, row", //多选    单选:"row"
            columns: [

                  {
                       field: "id",
                        template: "<input type='checkbox' id='#: id #' />"
                 },//带checkbox的

                { field: "EmployeeNo", title: "工号", width: "130px" },
                { field: "EmployeeName", title: "姓名", width: "130px" },
                { field: "Department", title: "部门", width: "130px" },
                {
                    field: "DutyDate", title: "日期", width: "130px",
                    template: "#= kendo.toString(new Date(DutyDate), 'yyyy-MM-dd') #"
                },
                { field: "ShiftName", title: "班次", width: "130px" },
                {
                    field: "BeginTime", title: "班次开始时间", width: "130px"
                    , template: "#= kendo.toString(new Date(BeginTime), 'yyyy-MM-dd HH:mm:ss') #"
                },
                {
                    field: "EndTime", title: "班次结束时间", width: "130px"
                    , template: "#= kendo.toString(new Date(EndTime), 'yyyy-MM-dd HH:mm:ss') #"
                },
                {
                    field: "CardBeginTime", title: "上班刷卡", width: "130px"
                    , template: "#= kendo.toString(new Date(CardBeginTime), 'yyyy-MM-dd HH:mm:ss') #"
                },
                {
                    field: "CardEndTime", title: "下班刷卡", width: "130px"
                    , template: "#= kendo.toString(new Date(CardEndTime), 'yyyy-MM-dd HH:mm:ss') #"
                },
                { field: "WorkHours", title: "应出勤时数", width: "130px" },
                { field: "FactWorkHours", title: "实出勤时数", width: "130px" },
                { field: "LateTimes", title: "迟到时数", width: "130px" },
                { field: "EarlyTimes", title: "早退时数", width: "130px" },
                { field: "AbsentCount", title: "旷工次数", width: "130px" },
                { field: "AbsentTimes", title: "旷工时数", width: "130px" },
                { field: "OverCount", title: "加班次数", width: "130px" },
                { field: "OverTimes", title: "加班时数", width: "130px" },
                { field: "LeaveCount", title: "请假次数", width: "130px" },
                { field: "LeaveTimes", title: "请假时数", width: "130px" },
                {
                    field: "OverFactBegin", title: "开始刷卡", width: "130px"
                    , template: "#=(OverFactBegin == null)? '': kendo.toString(new Date(OverFactBegin), 'yyyy-MM-dd HH:mm:ss') #"
                },
                {
                    field: "Visible", title: "是否可见", width: "130px"
                    , template: '<input type="checkbox" #=Visible ? " checked" : "" # disabled/>'
                },
                {
                    field: "IsDone", title: "是否经过异常处理", width: "130px",
                    template: function (item) {
                        if (item.IsDone == 1) {
                            return "是";
                        }
                        else {
                            return "否";
                        }
                    }
                },
            ]
        });
        $("#grid").data("kendoGrid").resize();

 

function Edit() {
            
            var grid = $("#grid").data("kendoGrid");
            if (grid.select().length == 0 || grid.select().length > 1 ) {
                alert("请选择一条要编辑的数据!");
                return;
            } 
            var url = "Edit?Id=" + grid.dataItem(grid.select()).Id;

            var myobjs = new Array(grid);

            ShowDialog(url, "修改", myobjs);
        }

function UpdateNormal() {
            var grid = $("#grid").data("kendoGrid");
            if (grid.select().length == 0 ) {
                alert("请选择要操作的数据!");
                return;
            } 
            var rows = grid.select();
            var nodes = [];
            rows.each(function () {
                var record = grid.dataItem($(this));
                nodes.push(record.Id);
            });

            $.ajax({
                url: '@Url.Action("UpdateStatus", "Day")',
                catch: false,
                data: 'Ids=' + nodes + '&status=' + true,
                success: function () {
                    grid.dataSource.read();
                    alert("更新完成。");
                },
                error: function () {
                    alert("更新失败。");
                }

            });
        }

后台:

public ActionResult Grid(int page, int pageSize, Sort[] sort, string departmentCode, int? employeeTypeId,string dataType, DateTime? startDate, DateTime? endDate)
        {

            //得到数据源list
            var list = _dayResultAppService.GetDayResult(departmentCode, employeeTypeId, dataType,startDate,endDate);
            //var functionlist = _cardAppService.GetAllCard();
            //根据排序字段排序
            if (sort != null && sort.Length > 0)
            {

                if (sort[0].Dir == "asc")
                    list = list.OrderBy(o => GetColString<DayResultDto>(o, sort[0].Field)).ToList();
                else
                    list = list.OrderByDescending(o => GetColString<DayResultDto>(o, sort[0].Field)).ToList();
            }
            //分页并返回json数据
            return this.Jsonp(new { data = list.Skip((page - 1) * pageSize).Take(pageSize), total = list.Count() });
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值