2013-04-16 18 views
1

的價值,我有以下模式:KendoUI定格模態驗證最大到另一列

... 
quantity: { 
      type: 'number', 
      validation: { 
       min: 0 
      } 
      } 
... 

在我的網格,您可以點擊要快速修改的值。我想要做的是,當數量字段被選中並準備好讓用戶開始輸入數字時,我希望最大可能值被設置爲返回到我的網格的另一列的值,例如quantityMax

quantityMax將在我的網格中的每一行不同。

我該怎麼做?輸入更改的處理程序是:

$('#salesGrid').on('change', '.k-input', function(){ 
    handleChange() 
}) 

function handleChange() 
{ 
    sGrid.dataSource.sync(); // Write changes. 
    sGrid.dataSource.read(); // Read updated grid. 
} 

回答

1

您可以使用quantity字段的編輯器功能來實現它。這是那麼容易,因爲:

columns : [ 
    // Other columns definition 
    { field: "quantityMax", title: "Max", width: 50 }, 
    { 
     width : 50, 
     title : "Quantity", 
     field : "quantity", 
     editor: function (container, options) { 
      // create an input element 
      var input = $("<input name='" + options.field + "'/>"); 
      // append it to the container 
      input.appendTo(container); 
      // initialize a Kendo UI numeric text box and set max value 
      input.kendoNumericTextBox({ 
       max: options.model.quantityMax 
      }); 
     } 
    } 
], 

時KendoUI在編輯模式下進入我產生一個輸入字段並設置maxquantityMax的價值,我從options.model明白我要做的就是。

對於的jsfiddle工作示例單擊here

+0

酷,如果我不想最大欄,顯示的是隱藏的列的參數? – imperium2335

+0

只需刪除'{field:「quantityMax」,標題:「Max」,寬度:50},'您不必在模型中顯示所有列。 – OnaBai

+0

你將如何使用mvc網格來做到這一點?可能嗎? –