简体   繁体   English

kendo网格数据源更改添加行递归

[英]kendo grid dataSource change add row recursion

I'm trying to add a row to my grid after it loads, but if I do the add row in the event-handler for the dataSource change event, it fires recursively 我正在尝试在加载后向网格中添加一行,但是如果我在事件处理程序中为dataSource change事件添加行,它将以递归方式触发

 $("#orderGrid").kendoGrid({
       dataSource: {
         transport: {
           read: "api/order-products"
         },
         pageSize: 10,
         change: function(e) {

            var grid = $("#orderGrid").data('kendoGrid');
            grid.dataSource.add( { name: "Product 1", orderId: "1" } );

         }  
       },
       columns:[{
         field: "name",
         title: "Product Name"
       }] 
     });

I also tried adding the add-row function to the dataBound event of the grid itself; 我还尝试将add-row函数添加到网格本身的dataBound事件中。 with the same result. 结果相同。

What's the right way to do this? 什么是正确的方法?

I've circumvented this by adding my own flag to the grid object; 我通过在网格对象中添加自己的标志来避免这种情况。 but this feels hacky - any cleaner suggestions welcome :S 但这感觉很棘手-欢迎任何更清洁的建议:S

        dataBound : function(e) { 
            var grid = $("#orderGrid").data('kendoGrid');
            if (!grid.productAdded) {
                grid.productAdded = true;
                grid.dataSource.add({
                    name : "Name",
                    orderId : "27"
                });
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM