Uncaught TypeError : cannot read property 'replace' of undefined In Grid

后端 未结 5 2191
暖寄归人
暖寄归人 2020-12-10 11:46

I\'m new in using Kendo Grid and Kendo UI . My question is how can i resolve this Error

Uncaught TypeError: Cannot read property \'replace\' of undefined 


        
相关标签:
5条回答
  • 2020-12-10 11:59

    I think jQuery cannot find the element.

    First of all find the element

    var rowTemplate= document.getElementsByName("rowTemplate");
    

    or

    var rowTemplate = document.getElementById("rowTemplate"); 
    

    or

    var rowTemplate = $('#rowTemplate');
    

    Then try your code again

    rowTemplate.html().replace(....)
    
    0 讨论(0)
  • 2020-12-10 12:00

    Please try with the below code snippet.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Test</title>
        <link href="http://cdn.kendostatic.com/2014.1.318/styles/kendo.common.min.css" rel="stylesheet" />
        <link href="http://cdn.kendostatic.com/2014.1.318/styles/kendo.default.min.css" rel="stylesheet" />
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://cdn.kendostatic.com/2014.1.318/js/kendo.all.min.js"></script>
        <script>
            function onDataBound(e) {
                var grid = $("#grid").data("kendoGrid");
                $(grid.tbody).find('tr').removeClass('k-alt');
            }
    
            $(document).ready(function () {
                $("#grid").kendoGrid({
                    dataSource: {
                        type: "odata",
                        transport: {
                            read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                        },
                        schema: {
                            model: {
                                fields: {
                                    OrderID: { type: "number" },
                                    Freight: { type: "number" },
                                    ShipName: { type: "string" },
                                    OrderDate: { type: "date" },
                                    ShipCity: { type: "string" }
                                }
                            }
                        },
                        pageSize: 20,
                        serverPaging: true,
                        serverFiltering: true,
                        serverSorting: true
                    },
                    height: 430,
                    filterable: true,
                    dataBound: onDataBound,
                    sortable: true,
                    pageable: true,
                    columns: [{
                        field: "OrderID",
                        filterable: false
                    },
                                "Freight",
                                {
                                    field: "OrderDate",
                                    title: "Order Date",
                                    width: 120,
                                    format: "{0:MM/dd/yyyy}"
                                }, {
                                    field: "ShipName",
                                    title: "Ship Name",
                                    width: 260
                                }, {
                                    field: "ShipCity",
                                    title: "Ship City",
                                    width: 150
                                }
                            ]
                });
            });
        </script>
    </head>
    <body>
        <div id="grid">
        </div>
    </body>
    </html>
    

    I have implemented same thing with different way.

    0 讨论(0)
  • 2020-12-10 12:03

    In my case, I was using a View that I´ve converted to partial view and I forgot to remove the template from "@section scripts". Removing the section block, solved my problem. This is because the sections aren´t rendered in partial views.

    0 讨论(0)
  • 2020-12-10 12:07

    It is important to define an id in the model

    .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Model(model => model.Id(p => p.id))
        )
    
    0 讨论(0)
  • 2020-12-10 12:14

    It could be because of the property pageable -> pageSizes: true.

    Remove this and check again.

    0 讨论(0)
提交回复
热议问题