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

时间:2013-11-25 07:43:21

标签: javascript jquery asp.net-mvc kendo-ui kendo-grid

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

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

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

        });

但我想根据Clicked DOM元素的值来设置第一个单元格的值,比如

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

但是在添加新行时没有直接显示值。点击其他元素后显示。 请建议我,这个是正确的方法,或者还有其他方法。

2 个答案:

答案 0 :(得分:11)

对于动态默认设置,您可以在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>

答案 1 :(得分:0)

  

根据Kendo团队的说法,默认值无法动态更改。

     

但是,我们可以使用Grid edit事件预先填充编辑表单:

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
 }

}

相关问题