2016-11-09 29 views
0

我有劍道子網格。它有一排。每行有一些單元格。如果我更改第一行以外的單元格的值,則必須獲取相應的第一行單元格值。這意味着如果我更改子網格中的第二行第二列值,我必須獲取該網格中的第一行第二列值。如何獲取第一行對應的單元格值,如果我更改了劍道子網格中的其他行單元格值

我已寫入子網格中每個單元格的更改事件。在更改任何單元格值時,此事件將觸發。在這種情況下,我想實現上述功能。屏幕截圖附上。

enter image description here

守則細胞的變化是

  $('<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"); 

回答

0

你有兩種方法可以做到這一點。您可以從單元格文本或dataItem中獲取值,這是我更喜歡的。

在你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

+0

謝謝DontVoteMeDown,但在這裏我面對小問題就改變事件。考慮這種情況下,在第一個單元格Thu日列中,我有0.如果我嘗試輸入任何其他行(2,3,...)爲星期四列,我必須阻止user.ie,如果他進入有些價值,我必須顯示警報消息,重點應該是當前單元格,但對於我點擊其他單元格警報正在觸發,焦點將在刪除警報後單擊單元格。如何防止用戶去其他單元格。我曾嘗試使用onchange事件,但它不起作用 – Gowthami

+0

@HarshavardhanReddy右側。這似乎是另一個問題,所以我建議你用相關的代碼創建另一個問題。當你創建時,請將這些評論發送給我,我會看看。嘗試添加更多可能的信息,如果按照我在答案中所做的那樣創建演示,則更好。 – DontVoteMeDown

+0

提出了新的問題,你可以看看那個 – Gowthami

相關問題