Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.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 TypeError:网格未定义_Javascript_Jquery_Kendo Grid - Fatal编程技术网

Javascript TypeError:网格未定义

Javascript TypeError:网格未定义,javascript,jquery,kendo-grid,Javascript,Jquery,Kendo Grid,我上传了一个发生错误的页面。它显示在控制台中(请在Firefox或Chrome浏览器中使用F12)。 这行是错误的:“kendo.stringify(grid.getOptions())” 我的问题:我必须如何更改此代码才能存储更改的表格设置 我也在这里插入html代码,谢谢回答 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta

我上传了一个发生错误的页面。它显示在控制台中(请在Firefox或Chrome浏览器中使用F12)。

这行是错误的:“kendo.stringify(grid.getOptions())”

我的问题:我必须如何更改此代码才能存储更改的表格设置

我也在这里插入html代码,谢谢回答

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">  
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.common.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.rtl.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.default.min.css"> 
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.dataviz.min.css">
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.dataviz.default.min.css">

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>       
    <script src="http://cdn.kendostatic.com/2014.3.1411/js/jszip.min.js"></script>
    <script src="http://cdn.kendostatic.com/2014.3.1411/js/kendo.all.min.js"></script>

    <style type="text/css">
        .button-center {
            text-align: center; /* button position in grid */
        }
    </style>
</head>

<body role="document">

    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">WebSiteName</a>
            </div>
            <div>
                <ul class="nav navbar-nav">
                    <li class="active"><a href="index.php">one</a></li>
                    <li><a href="next.php">two</a></li>
                </ul>
            </div>
        </div>
    </nav>  

    <div class="container theme-showcase" id="main" role="main">

        <div class="container">
            <h1>Page<small> one</small></h1> 
        </div>

        <div class="row-fluid">
            <div id="grid_one"></div>   
        </div> <!-- row -->

        <div class="row-fluid">
            <div id="log"></div>
        </div> <!-- row -->

    </div> <!-- container -->
<script>
<!-- --------------------------------------------------------------------------------- --> 
var firstNames = ["Nancy", "Andrew", "Janet", "Margaret", "Steven", 
                  "Michael", "Robert", "Laura", "Anne", "Nige"],
    lastNames = ["Davolio", "Fuller", "Leverling", "Peacock", "Buchanan", 
                 "Suyama", "King", "Callahan", "Dodsworth", "White"],
    cities = ["Seattle", "Tacoma", "Kirkland", "Redmond", "London", 
              "Philadelphia", "New York", "Seattle", "London", "Boston"],
    titles = ["Accountant", "Vice President, Sales", "Sales Representative", 
              "Technical Support", "Sales Manager", "Web Designer",
              "Software Developer", "Inside Sales Coordinator", "Chief Techical Officer", 
              "Chief Execute Officer"],
    birthDates = [new Date("1948/12/08"), new Date("1952/02/19"), new Date("1963/08/30"), 
                  new Date("1937/09/19"), new Date("1955/03/04"), new Date("1963/07/02"), 
                  new Date("1960/05/29"), new Date("1958/01/09"), new Date("1966/01/27"), 
                  new Date("1966/03/27")];

function createRandomData(count) {
    var data = [], now = new Date();

    for (var i = 0; i < count; i++) {
        var firstName = firstNames[Math.floor(Math.random() * firstNames.length)],
            lastName = lastNames[Math.floor(Math.random() * lastNames.length)],
            city = cities[Math.floor(Math.random() * cities.length)],
            title = titles[Math.floor(Math.random() * titles.length)],
            birthDate = birthDates[Math.floor(Math.random() * birthDates.length)],
            age = now.getFullYear() - birthDate.getFullYear();

        data.push({
            Id: i + 1,
            FirstName: firstName,
            LastName: lastName,
            City: city,
            Title: title,
            BirthDate: birthDate,
            Age: age
        });
    }
    return data;
}
<!-- --------------------------------------------------------------------------------- --> 
function onChangeSelection() {
    var selectedItem = this.dataItem(this.select());
    var Text = '<h1><small>row name=</small>' + selectedItem.FirstName + " " + selectedItem.LastName + "</h1>";
    console.log(Text);
    $("#log").html(Text);
    $("#ordernumber").val(selectedItem.ordernumber);
}
<!-- --------------------------------------------------------------------------------- --> 
function startbuttonclick(e) {      
    var data = this.dataItem($(e.currentTarget).closest("tr"));
    var Text = "<h1><small>Button click name=</small> " + data.FirstName + " " + data.LastName + "</h1>";       
    console.log(Text); 
    $("#log").html(Text);
    e.preventDefault();                         
}
<!-- --------------------------------------------------------------------------------- --> 
$(document).ready(function() {
    $("#grid_one").kendoGrid({
        dataSource: {
            data: createRandomData(10),
            schema: {
                model: {
                    fields: {
                        FirstName: { type: "string" },
                        LastName: { type: "string" },
                        City: { type: "string" },
                        Title: { type: "string" },
                        BirthDate: { type: "date" },
                        Age: { type: "number" }
                    }
                }
            },
            pageSize: 10
        },
        height: 500,
        dataBound: saveState,
        columnResize: saveState,
        columnShow: saveState,
        columnHide: saveState,
        columnReorder: saveState,
        columnLock: saveState,
        columnUnlock: saveState,        
        selectable: true,
        resizable: true,
        columnMenu: true,
        scrollable: true,
        sortable: true,
        filterable: true,
        change: onChangeSelection,            
        pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5,
            pageSizes: [5, 10, 20, 250]
        },
        columns: [
            {
                field: "FirstName",
                title: "First Name",
                width: "150px",
            },
            {
                field: "LastName",
                title: "Last Name",
                width: "150px",
            },
            {
                field: "City",
                hidden: true
            },
            {
                field: "Title",
                hidden: true
            },
            {
                field: "BirthDate",
                title: "Birth Date",
                template: '#= kendo.toString(BirthDate,"MM/dd/yyyy") #',
                width: "175px",
            },
            {
                field: "Age",
                width: "150px",
            },
            {
                command: { 
                    text: "Start", 
                    click: startbuttonclick }, 
                        title: "Start", 
                        width: "65px",
                    attributes:{
                        "class":"button-center"}            
            }
        ]
    });
    <!-- ------------------------------------------------------------------------------ -->     
    var grid = $("#grid_one").data("kendoGrid");

    function saveState(e) {
        e.preventDefault();
        localStorage["kendo-grid-one"] = kendo.stringify(grid.getOptions());
    };

    $(function (e) {
        var options = localStorage["kendo-grid-one"];
        if (options) {
            grid.setOptions(JSON.parse(options));
        } else {
          grid.dataSource.read();
        }
    }); 
});
<!-- --------------------------------------------------------------------------------- --> 
</script>
</body>
</html>

.按钮中心{
文本对齐:居中;/*按钮在网格中的位置*/
}
第一页 var firstNames=[“南希”、“安德鲁”、“珍妮特”、“玛格丽特”、“史蒂文”, “迈克尔”、“罗伯特”、“劳拉”、“安妮”、“奈吉”], lastNames=[“达沃利奥”、“富勒”、“勒沃林”、“孔雀”、“布坎南”, “素山”、“国王”、“卡拉汉”、“多兹沃思”、“怀特”], 城市=[“西雅图”、“塔科马”、“科克兰”、“雷蒙德”、“伦敦”, “费城”、“纽约”、“西雅图”、“伦敦”、“波士顿”], 职位=[“会计”、“销售副总裁”、“销售代表”, “技术支持”、“销售经理”、“网页设计师”, “软件开发人员”、“内部销售协调员”、“首席技术官”, “首席执行官”], 生日=[新日期(“1948/12/08”)、新日期(“1952/02/19”)、新日期(“1963/08/30”), 新日期(“1937/09/19”)、新日期(“1955/03/04”)、新日期(“1963/07/02”), 新日期(“1960/05/29”)、新日期(“1958/01/09”)、新日期(“1966/01/27”), 新日期(“1966/03/27”); 函数createRandomData(计数){ var data=[],now=新日期(); 对于(变量i=0;ivar grid = null; $("#grid_one").kendoGrid({ ... }); grid = $("#grid_one").data("kendoGrid"); function saveState(e) { e.preventDefault(); grid && localStorage["kendo-grid-one"] = kendo.stringify(grid.getOptions()); };
$(document).ready(function() {
  // Get options first
  var options = localStorage["kendo-grid-one"];
  if (options) {
    options = JSON.parse(options);
    // Workaround to addback event
    options.columns[6].command.click = startbuttonclick;
  }

  $("#grid_one").kendoGrid({
        dataSource: {
            data: createRandomData(10),
            schema: {
            .....
    });
  if (options) {
    $("#grid_one").data("kendoGrid").setOptions(options);  
  }
  <!-- ------------------------------------------------------------------------------ -->     

  function saveState(e) {
    var grid = $("#grid_one").data("kendoGrid");
    e.preventDefault();
    localStorage["kendo-grid-one"] = kendo.stringify(grid.getOptions());
  };
function saveState(e) {
    e.preventDefault();
    localStorage["kendo-grid-one"] = kendo.stringify(this.getOptions());
};