【问题标题】:Default styles not being applied in jqGridjqGrid 中未应用默认样式
【发布时间】:2013-07-02 23:30:17
【问题描述】:

我正在尝试来自http://www.trirand.com/blog/jqgrid/jqgrid.html 的 jqGrid 示例。网格带有数据,但不应用默认样式(字体大小、不同块/行的高度等)。默认样式是指我在 trirand 站点中使用的示例中看到的样式。

我该如何解决这个问题?

谢谢 维韦克·拉古纳坦

我使用的代码:

<html>
<head>
    <title>JQGrid</title>
    <link rel='stylesheet' type='text/css' href='http://code.jquery.com/ui/1.10.3/themes/sunny/jquery-ui.css' />
    <link rel='stylesheet' type='text/css' href='http://www.trirand.com/blog/jqgrid/themes/ui.jqgrid.css' />

    <script type='text/javascript' src='http://localhost:82/testbed/resources/jquery-1.7.1.min.js'></script>
    <script type='text/javascript' src='http://www.trirand.com/blog/jqgrid/js/jquery-ui-custom.min.js'></script>        
    <script type='text/javascript' src='http://www.trirand.com/blog/jqgrid/js/i18n/grid.locale-en.js'></script>
    <script type='text/javascript' src='http://www.trirand.com/blog/jqgrid/js/jquery.jqGrid.js'></script>

    <script type="text/javascript">
        var lastsel2;

        $(function () {
            $("#list1").jqGrid({
                caption: "Trying out jqGrid for Points",
                url: <url>,
                editurl: <edit url>,
                mtype : "get",
                datatype: "json",
                colNames: ['id', 'Name', 'Age', 'Address'],
                colModel: [
                    { name:'id',        index: 'id',        width: 35, align:"left", editable: true, sorttype: 'int', editrules: { edithidden: true }, hidden: true },
                    { name: 'name',     index: 'name',      width: 35, align:"left", editable: true, editoptions: { size: '20', maxlength: '255'} },
                    { name: 'age',      index: 'name',      width: 35, align:"left", editable: true, editoptions: { size: '20', maxlength: '255'} },
                    { name: 'address',  index: 'address',   width: 35, align:"left", editable: true, editoptions: { size: '20', maxlength: '255'} },
                ],
                rowNum: 10,
                autowidth: true,
                height: 150,
                rowList: [10, 20, 30, 50, 80, 100],
                pager: '#pager1',
                toolbar: [true,"top"],
                sortname: 'created',
                viewrecords: true,
                altRows: true
            });

            $("#list1").jqGrid('navGrid', '#pager1', { edit: true, add: true, del: false });
        });
        }
    </script>

</head>

<body>
    <table id="list1"></table>
    <div id="pager1"></div>
</body>

【问题讨论】:

    标签: html jqgrid


    【解决方案1】:

    我认为所描述问题的原因可能是在&lt;html&gt; 之前缺少&lt;!DOCTYPE html ...&gt; 行。向 Web 浏览器提供清晰的信息非常重要,您在页面上使用的 HTML/XHTML 语言的版本和方言。您在页面上使用&lt;link ... /&gt;。因此,您可能尝试用 XHTML 语言编写代码。在这种情况下,您可以使用类似

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    

    而不是&lt;html&gt;

    此外,我建议您包括这些行

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    

    &lt;head&gt; 的开头(例如来自the documentation 的示例)。如果您从 Internet 加载其他 JavaScript 文件,那么您也可以从 http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.jshttp://code.jquery.com/jquery-1.10.1.min.js 加载 jQuery。

    您没有编写您使用的 jqGrid 版本。您应该使用最新的版本(目前是 4.5.2)并包含 jquery.jqGrid.min.jsjquery.jqGrid.src.js 而不是 jquery.jqGrid.js

    我建议您在所有网格中使用gridview: trueautoencode: true 选项。 height: "auto" 的用法似乎也不错。我认为选项sortname: 'created' 是一个复制和粘贴错误。您应该使用网格中某个现有列的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多