这是数据绑定后 Kendo 网格中的最后一个事件

which is the last event in Kendo grid after databound

我正在处理 kendo 网格,在其数据绑定事件中,我调用了一个函数来检查每个行的第二个块中的值是否大于第一个块。如果为真,那么我会通过添加 class 来更改内部文本的颜色。 但是,问题是当我在浏览器上看到时,添加的 class 终于消失了。 如果有两行有错误,我正在编辑的第一行不包含 class 但后面的行则很好。

 dataBound: configureGridProperties,

dataBound 的代码是

    function configureGridProperties(e) {
    try {
        if (true) {
            $('#grid .k-grid-content tr[role=row]').each(function (i) {
                var sh = $(this).find('.sh').text();
                var sm = $(this).find('.sm').text()
                var eh = $(this).find('.eh').text()
                var em = $(this).find('.em').text()
                var startMin = parseInt(sh) * 60 + parseInt(sm);
                var endMin = parseInt(eh) * 60 + parseInt(em);
                if (startMin > endMin) {
                    showOutputExplicitly('Start time cannot be less than end time');
                    
                 
                  $(this).find('.sh, .sm,.eh,.em').addClass('timeError');
                    $('div.k-grid-pager').hide();
             
                    errorInTime = false;
                }
                else {
                       $(this).find('.sh, .sm,.eh,.em').removeClass('timeError');                      
                    if (!$('.timeError').length > 0) {
                        $('div.k-grid-pager').show();
                        hideErrorMsgSlow();
                        errorInTime = true;
                    }
                }
            });
        }          
        return false;
    } catch (e) {
    }

情况图片。 >

我刚刚编辑的第二行(开始时间 23)不包含 colorChange class,但较早的行包含该内容。 dataBound 事件之后是否还有其他事件发生?

碰巧调用 dataBound 时,网格 html 元素尚未使用新数据呈现。我知道这很奇怪,但我不知道除了使用 setTimeout 来完成这项工作之外的其他方法。所以这可能有效:

dataBound: function(e) {
    window.setTimeout(configureGridProperties.bind(this, e), 1);
}

参考: