Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 默认情况下如何将空的最后一行添加到剑道Ui网格_Javascript_Jquery_Kendo Ui_Kendo Grid_Kendo Ui Grid - Fatal编程技术网

Javascript 默认情况下如何将空的最后一行添加到剑道Ui网格

Javascript 默认情况下如何将空的最后一行添加到剑道Ui网格,javascript,jquery,kendo-ui,kendo-grid,kendo-ui-grid,Javascript,Jquery,Kendo Ui,Kendo Grid,Kendo Ui Grid,默认情况下,我需要在编辑模式下将空的最后一行添加到剑道UI网格。我正在从api获取数据,如果我最后尝试添加空行,它将首先被调用,api将在之后被调用。我如何才能做到这一点。我不想设置超时。我尝试在数据源中添加空记录,但为此我需要做很多事情 var dataSource = new kendo.data.DataSource({ type: "odata", serverPaging: false,

默认情况下,我需要在编辑模式下将空的最后一行添加到剑道UI网格。我正在从api获取数据,如果我最后尝试添加空行,它将首先被调用,api将在之后被调用。我如何才能做到这一点。我不想设置超时。我尝试在数据源中添加空记录,但为此我需要做很多事情

var dataSource = new kendo.data.DataSource({
                type: "odata",
                serverPaging: false,
                serverSorting: false,
                serverFiltering: false,
                //pageSize: 20,
                schema: {
                    data: function (data) {
                        var resultData = [];
                        if (data.value != null && data.value[0].Payload != null && data.value[0].Payload != "[]")
                            resultData = JSON.parse(data.value[0].Payload);
                        return resultData;
                    },
                    total: function (data) {
                        var length = 0;
                        if (data.value != null)
                            length = data.value[0].PayloadCount;
                        return length;

                    },
                    model: {
                        id: that.gridProperties.PrimaryKeyName,
                        fields: that.gridProperties.Schema
                    }

                },
                change: that.onGridDataChanged,
                transport: {
                    read: {

                        url: that.gridProperties.DataSourceURL,
                        contentType: "application/json; charset=utf-8",
                        type: "GET",
                        dataType: "json"
                    }
                }
            });         
  $('#' + that.gridProperties.ControlId).kendoGrid({
                height: "100%",
                scrollable: true,
                filterable: true,
                sortable: true,
                resizable: true,
                pageable: false,
                noRecords: true,
                editable: that.gridProperties.Editable,
                selectable: !that.gridProperties.AllowMultiSelect, //If multiselect is false enable row selection
                columns: gridColumns,
                dataSource: dataSource,
                edit: that.onGridEdit,
                // This is required to update the calculated column as soon as user enters/types new values 
                save: function (e) {
                    var dataSource = this.dataSource;
                    that.updateFormulaColumn(e, dataSource);

                    e.model.one("change", function () {
                        dataSource.fetch();
                    });
                },
               
            });
            var grid = $('#' + that.gridProperties.ControlId).data("kendoGrid");
            grid.addRow()
尝试使用数据源的事件。您可以在数据列表的末尾添加一个空行:


html{字体大小:14px;字体系列:Arial、Helvetica、sans serif;}
$(文档).ready(函数(){
$(“#网格”).kendoGrid({
数据源:{
类型:“odata”,
运输:{
阅读:“https://demos.telerik.com/kendo-ui/service/Northwind.svc/Categories"
},
requestEnd:函数(e){
e、 response.d.results.push({CategoryName:''});
}
},
身高:550,
可过滤:正确,
可排序:是的,
pageable:对,
栏目:[
“类别名称”
]
});
});

您可以使用requestEnd设置数据源,以便在网格行数据的末尾添加一个空行

        dataSource: {
            type: "GET",
            dataType: "json",
            transport: {
                read: "url"
            },
            requestEnd: function(e) {
              e.response.d.results.push({Field: ''});
            }
        }
此外,这会导致空单元格的行为不同,并且具有较小的高度,您可以通过添加以下css来解决此问题

        .k-grid tr{height: 33px;}

默认情况下,没有魔法,网格渲染行不是凭空想象的,因为它渲染的是数据源,所以添加到数据源中。即使使用按钮添加新行,它也会作为空行进入数据源。