简体   繁体   English

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

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

I want to add new Row in Kendo Grid which is having Default value in First Cell. 我想在Kendo Grid中添加新行,它在First Cell中具有默认值。 How can I set the Default Value in that added Row of Kendo Grid 如何在添加的Kendo Grid行中设置默认值

I am adding New Row in Kendo Grid as:: 我在Kendo Grid中添加了New Row ::

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

        });

But I want to Set the Value of First cell on the Basis of Value of Clicked DOM element, Like 但我想在Clicked DOM元素的值的基础上设置第一个单元格的值,Like

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

But we can't do it in that Manner. 但我们不能以那种方式去做。 So please help me on this, For adding New Row in Kendo Grid with one Cell having Value of Button clicked. 所以,请帮助我,在Kendo Grid中添加New Row,单击一个具有按钮值的单元格。

Now I am able to Add New Row in Kendo Grid as, 现在我可以在Kendo Grid中添加新行了,

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

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

But the Value is not Directly Shown while adding new Row. 但是在添加新行时没有直接显示值。 It is Shown after we click on some other element. 点击其他元素后显示。 Please Suggest me wether this one is the Correct way to do this or there is any other way than this. 请建议我这个是正确的方法,或者除此之外还有其他任何方式。

For dynamic defaults you can wire up your logic on Edit event, something like: 对于动态默认值,您可以在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>

As per Kendo team , Default value cannot be changed dynamically. 根据Kendo团队,默认值无法动态更改。

However, we can make use the Grid edit event to pre-populate the edit form: 但是,我们可以使用网格编辑事件来预先填充编辑表单:

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