1

我现在有一个问题,我有一个只有两种日期类型的可编辑字段的 Kendo UI Grid,到目前为止一切正常。给我的问题是验证开始日期和结束日期。日期必须始终小于或等于结束日期。我需要验证这两个字段。有想法的人谢谢 在此处输入图像描述

dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            url: controller + "/read",
            type: "GET"
        },
        update: {
            url: controller + "/update",
            type: "POST",
            dataType: "json"

            //data: { model: "prueba" }
        },
        destroy: {
            url: controller + "/delete",
            dataType: "json",
            type: "POST"
        }
    },
    batch: true,
    //pageSize: 10,
    schema: {
        model: {
            id: "id_POSPlanningOpe",
            fields: {
                select: { type: "boolean", editable: false },
                id_POSPlanningOpe: { editable: false, nullable: true },
                codPdv: { editable: false },
                nombrePdv: { editable: false },
                regionPdv: { editable: false },
                zonapdv: { editable: false },
                fecha_Inicio: { type: "date", editable: true },
                fecha_Fin: { type: "date", editable: true },
                estado: { editable: false }
            }
        }
    }
});

$("#grid").kendoGrid({
    selectable: "multiple",
    sortable: {
        mode: 'single',
        allowUnsort: false
    },
    dataSource: dataSource,
    height: 500,
    toolbar: [
        { name: "save", text: "Grabar" },
        { name: "cancel", text: "Cancelar" }],
    columns: [
        { title: "<span></span>", width: "20px", template: '<input type="checkbox" name="CheckRow" value="#= id_POSPlanningOpe #"></input>' },
        { field: "id_POSPlanningOpe", title: "<span class='Cabecera'>NRORUTA</span>", width: 80 },
        { field: "codPdv", title: "<span class='Cabecera'>CODIGO PDV</span>", width: 100 },
        { field: "nombrePdv", title: "<span class='Cabecera'>NOMBRE</span>" },
        { field: "regionPdv", title: "<span class='Cabecera'>REGION</span>" },
        { field: "zonapdv", title: "<span class='Cabecera'>ZONA</span>" },
        { field: "fecha_Inicio", title: "<span class='Cabecera'>FECHA INICIO</span>", template: '#= kendo.toString(fecha_Inicio,"dd/MM/yyyy") #', width: 100 },
        { field: "fecha_Fin", title: "<span class='Cabecera'>FECHA FIN</span>", template: '#= kendo.toString(fecha_Fin,"dd/MM/yyyy") #', width: 100 },
        { field: "estado", title: "<span class='Cabecera'>ESTADO</span>", width: 80 },
        { command: ["edit"], title: "&nbsp;", width: "100px" }],
    editable: 'inline'

}); 
4

2 回答 2

2

您可以尝试实现自定义验证规则,如下所示

或者,您可以使用 Grid 的编辑事件来检查值是否处于有效状态,如果不是,您可以阻止 Grid 关闭并通知用户出了什么问题。

于 2012-12-11T21:39:41.150 回答
0

我已经使用此功能完成了此操作:

(function ($, kendo) {
    $.extend(true, kendo.ui.validator, {
        rules: { // custom rules
            startdatetimevalidation: function (input, params) {
                if ($(input).val() && $(input).attr('id') == "StartDateTime") {
                    if ($('#EndDateTime').val() && $(input).getKendoDateTimePicker().value() > $('#EndDateTime').getKendoDateTimePicker().value()) {
                        return false;
                    }
                }
                return true;
            },
            endatetimevalidation: function (input, params) {
                if ($(input).val() && $(input).attr('id') == "EndDateTime") {
                    if ($('#StartDateTime').val() && $(input).getKendoDateTimePicker().value() < $('#StartDateTime').getKendoDateTimePicker().value()) {
                        return false;
                    }
                }
                return true;
            }
        },
        messages: {
            startdatetimevalidation: function (input) {
                return "Start Date can't be greater than End Date.";
            },
            endatetimevalidation: function (input) {
                return "End Date can't be smaller than Start Date.";
            }
        }
    });
})(jQuery, kendo);

希望这有帮助!我知道这篇文章很旧,但也许有人也需要这个..

如果您需要更多信息,请参阅此页面: http ://demos.telerik.com/aspnet-mvc/grid/editing-custom-validation

于 2015-09-04T18:11:35.047 回答