【问题标题】:Display a database table in a jqGrid在 jqGrid 中显示数据库表
【发布时间】:2017-11-21 09:58:40
【问题描述】:

我正在拼命地尝试在我创建的 jqGrid 中显示我的数据库中的数据,但我真的不明白它是如何工作的。

我仔细阅读了有关 jqGrid 的文档并尝试调整官方网站的演示,但我找不到简单的方法来用 PHP/MySQL 或 AJAX 脚本替换网格的“数据”选项。这是我的代码:

    <script>
        $(function (){
            $("#grid").jqGrid({
                colNames: ["ID", "Context", "IP", "Community", "Modèle", "Uptime", "Version Soft", "Version Patch", "Date d'ajout", "Date modif", "Refresh"],
                colModel: [
                    {name:'id', index:'id', width:60, sorttype:'int', align:'center'},
                    {name:'context', index:'context', width:130, align:'center'},
                    {name:'ip', index:'ip', width:150, align:'center'},
                    {name:'community', index:'community', width:100, align:'center'},
                    {name:'modele', index:'modele', width:80, align:'center'},
                    {name:'uptime', index:'uptime', width:150, align:'center'},
                    {name:'soft', index:'soft', width:150, align:'center'},
                    {name:'patch', index:'patch', width:150, align:'center'},
                    {name:'ajout', index:'ajout', width:100, sorttype:'date', align:'center'},
                    {name:'modif', index:'modif', width:100, sorttype:'date', align:'center'},
                    {name:'refresh', index:'refresh', width:70, align:'center', formatter:refresh_Button}
                ],
                data: [
                    {id:"1",context:"LAB",ip:"192.168.xx.xx",community:"public",modele:"S57",ajout:"20-11-2017"}
                ],
                caption: "Equipements disponibles :",
                sortname: 'id',
                sortorder:"desc",
                rowNum:20,
                rowList:[20,40,60],
                pager:'#yolo'
            });
            function refresh_Button(cellvalue, options, rowobject){
                return '<button type="button" onclick="">Go</button>';

            }

        });
    </script>
</head>

<body>
<table id="grid"></table>
<div id="yolo"></div>
</body>
</html>

有谁知道如何做这样的事情?

【问题讨论】:

    标签: javascript php ajax database jqgrid


    【解决方案1】:

    以防万一人们想知道答案,您必须:

    1. 在您的 jqGrid 选项中添加这些参数:

    url:"your_ajax_page.php"

    mtype:"POST" //或 GET

    数据类型:“json”

    加载一次:“真”

    1. 创建 your_ajax_page.php 并基本上复制官方 jqGrid 演示网站上的“loadonce”演示(目前已关闭)。

    2. 链接数据库数据和 jqGrid 行后,在页面底部添加“echo json_encode($data_array)

    3. 应该是这样,希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多