【问题标题】:How to get the first row corresponding cell value if i change the other rows cell value in kendo child grid如果我更改剑道子网格中的其他行单元格值,如何获取第一行对应的单元格值
【发布时间】:2016-11-09 09:40:28
【问题描述】:

我有剑道子网格。它有一些行。每行都有一些单元格。如果我更改第一行以外的单元格的值,我必须获得相应的第一行单元格值。这意味着如果我更改子网格中的第二行第二列值,我必须获取该网格中第一行第二列的值。

我已经编写了子网格中每个单元格的更改事件。在更改任何单元格值时,将触发此事件。在这种情况下,我想实现上述功能。附上屏幕截图。

更改单元格的代码是

           $('<input  maxlength="9" data-bind="value:' + options.field + '"/>')
                .appendTo(container)
                .kendoNumericTextBox({
                    format: "0.####",
                    decimals: 0,
                    min: 0,
                    spinners: false,
                    change: function (e) {
                        //Here i want to get the first row of this cell value
                    }
                }).off("keydown");

【问题讨论】:

    标签: kendo-ui


    【解决方案1】:

    您有两种方法可以做到这一点。您可以从单元格文本或数据项中获取值,我更喜欢。

    在你的 editor 函数中试试这个:

    function(container, options) {
        var $container = $(container),
            tdIndex = $container.index(),
            $correspondingCell = $container.closest("tbody").find("tr:first td:eq(" + tdIndex + ")"),
            dataItem = grid.dataItem($correspondingCell.parent()),
            correspondingColumnName = options.field;
    
        // Get from cell's text
        console.log("From Cell", $correspondingCell.text());
    
        // Get from dataItem
        console.log("From DataItem", dataItem[correspondingColumnName]);
    
        $('<input  maxlength="9" data-bind="value:' + options.field + '"/>')
            .appendTo($container)
            .kendoNumericTextBox({
                format: "0.####",
                decimals: 0,
                min: 0,
                spinners: false,
                change: function (e) {
                    // Now this is the corresponding cell's value from first row
                    console.log("First row's corresponding cell value", this);
                }.bind(dataItem[correspondingColumnName]) // <- bind the dataItem's property to the change event
            }).off("keydown");
    }
    

    Demo

    【讨论】:

    • 谢谢DontVoteMeDown,但我在更改事件方面遇到了小问题。考虑这种情况,在第一个单元格 Thu day 列中我有 0。如果我尝试为 Thu day 列输入任何其他行(2,3,...),我必须阻止 user.ie 如果他输入一些值我必须显示警报消息,并且焦点应该是当前单元格,但对我来说,单击其他单元格警报正在触发,并且在删除警报后焦点将转到单击的单元格。如何防止用户去其他单元格。我曾尝试使用 onchange 事件,但它不起作用
    • @HarshavardhanReddy 对。这似乎是另一个问题,所以我建议您使用相关代码创建另一个问题。当您创建时,将这些 cmets 发送到这里,我会看看。尝试添加更多信息,如果您像我在回答中所做的那样创建演示,效果会更好。
    • 提出了新问题,你能看看吗
    • @HarshavardhanReddy 我肯定会的。
    猜你喜欢
    • 1970-01-01
    • 2017-06-28
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多