使用一些默认值在剑道网格中添加新行

Add new Row in Kendo Grid with some default values

本文关键字:网格 添加 新行 默认值      更新时间:2023-09-26

我想在剑道网格中添加新行,该行在第一个单元格中具有默认值。如何在添加的剑道网格行中设置默认值

我在剑道网格中添加新行为::

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

但我想根据点击的DOM元素的值来设置第一个单元格的值,就像一样

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

但我们不能那样做。所以请帮助我,在剑道网格中添加新行,其中一个单元格的值为按钮点击。

现在我可以在剑道网格中添加新行作为

$("#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>

根据剑道团队的说法,默认值不能动态更改。

然而,我们可以使用网格编辑事件来预填充编辑表单:

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
 }

}