簡體   English   中英

使用一些默認值在Kendo Grid中添加新行

[英]Add new Row in Kendo Grid with some default values

我想在Kendo Grid中添加新行,它在First Cell中具有默認值。 如何在添加的Kendo Grid行中設置默認值

我在Kendo Grid中添加了New Row ::

 $('#AddSingleSuppliment').click(function () {
            grid.addRow();

        });

但我想在Clicked DOM元素的值的基礎上設置第一個單元格的值,Like

 $('#AddSingleSuppliment').click(function () {
           var temVal=$(this).text();
           grid.addRow(tempVal);
        });

但我們不能以那種方式去做。 所以,請幫助我,在Kendo Grid中添加New Row,單擊一個具有按鈕值的單元格。

現在我可以在Kendo Grid中添加新行了,

$("#AddSingleSupplement").click( function(){
            var tempSupplement = $(this).val();
            //alert(tempSupplement);

            grid.addRow(tempSupplement);
            grid.dataSource._data[0].Description = $(this).text().trim();
        });

但是在添加新行時沒有直接顯示值。 點擊其他元素后顯示。 請建議我這個是正確的方法,或者除此之外還有其他任何方式。

對於動態默認值,您可以在Edit事件上連接邏輯,例如:

<script>

    $('#AddSingleSuppliment').click(function () {
            grid.addRow();    
        });

    function onEdit(e)
    {
        //Custom logic to default value
        var name = $("#AddSingleSuppliment").text();

        // If addition
        if (e.model.isNew()) {
            //set field
            e.model.set("Name", name); // Name: grid field to set
        }
    }
</script>

根據Kendo團隊,默認值無法動態更改。

但是,我們可以使用網格編輯事件來預先填充編輯表單:

edit: function(e) {
 if (e.model.isNew() && !e.model.dirty) {
   e.container
     .find("input[name=ProductName]") // get the input element for the field
     .val("MyCustomValue") // set the value
     .change(); // trigger change in order to notify the model binding
 }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM