Kendo Grid自定义工具栏按钮启用/禁用 [英] Kendo Grid Custom Toolbar button Enable/Disable

查看:91
本文介绍了Kendo Grid自定义工具栏按钮启用/禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工具栏面板中有一个带有保存按钮的剑道网格.我有一个建议的折扣列,该列是可编辑的,并且如果用户输入0到100之间的整数(不包括小数),则保存按钮应该是可见的或启用的,否则是不可见的或禁用的.我能够使按钮不可见或禁用,但是当它们输入正确的值时,按钮将不可见或未启用.请帮我.我最近刚开始从事Kendo UI的工作.

I have a kendo grid with save button in the Tool bar panel. I have a proposed discount column which is editable and if the user enters whole numbers between 0 and 100(excluding decimals) , the save button should be visible or enabled otherwise invisible or disabled. I was able to achieve making the button invisible or disable but when they enter correct value, the button was not getting visible or enabled. Please help me. I just started working on Kendo UI recently.

function setEnabled(enabled) {
    if (enabled) {
        // $(".k-grid-nstToolbarBtn").removeClass("k-state-disabled");
        $(".k-grid-nstToolbarBtn").show();
    }
    else {
        // $(".k-grid-nstToolbarBtn").addClass("k-state-disabled");
        $(".k-grid-nstToolbarBtn").removeAttr("href");
        $(".k-grid-nstToolbarBtn").hide();
    }
}



$('#NSTGrid').kendoGrid({
           toolbar: [{ type: "button", text: "Save", name: "nstToolbarBtn", className: "k-grid-saveData" }],
           dataSource: {
               data: data.ReportData,
               schema: {
                   model: {
                       fields: {

                           ProposedDiscount: {
                               validation: { 
                                   required: true,
                                   proposeddiscountvalidationcvalidation: function (input) {
                                       if (input.val() != "" && input.is("[name='ProposedDiscount']")) {
                                           input.attr("data-proposeddiscountvalidationcvalidation-msg", "Proposed Discount should be whole number");
                                           setEnabled(false);
                                           return input.val() >= 0 && input.val() < 101 && input.val() % 1 == 0;

                                       } else {


                                           setEnabled(true);
                                           return true;
                                       }
                                   }
                               }
                           },


                           ProductApprovedDiscount: { type: "decimal", editable: false },
                           BAN: { type: "string", editable: false },

推荐答案

我认为传递给setEnabled函数的值必须与作为验证结果返回的值相同.请尝试以下更改:

I think the value passed to your setEnabled function needs to be the same as what you return as the validation result. Please try the following change:

proposeddiscountvalidationcvalidation: function (input) {
    if (input.val() != "" && input.is("[name='ProposedDiscount']")) {
        input.attr("data-proposeddiscountvalidationcvalidation-msg", "Proposed Discount should be whole number");
        var valid = input.val() >= 0 && input.val() < 101 && input.val() % 1 == 0;
        setEnabled(valid);
        return valid;
    } else {
        return true;
    }
}

这篇关于Kendo Grid自定义工具栏按钮启用/禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆