【问题标题】:ParamQuery Data DisplayParamQuery 数据展示
【发布时间】:2014-06-15 00:14:54
【问题描述】:

我正在尝试在 php 中实现 ParamQuery 一个类似 excel 的插件。我正在尝试从生成 json 输出的 php 中获取数据。它正在正确获取,但我想在指定的 div:grid_array 中显示数据格式。我无法做到这一点所有字段都变为空白。

我的json输出代码:data.php

<?php
 $conn = mysql_connect('localhost','root','pass');
 if(!$conn){
  die('Mysql connection error '.mysql_error());
 }

 $db = mysql_select_db('pop',$conn);
 if(!$db){
  die('Database selection failed '.mysql_error());
 }

 $sql = 'SELECT *FROM items';

 $result = mysql_query($sql,$conn);


 $data = array();
 while($row = mysql_fetch_array($result)){
  $row_data = array(
   'id' => $row['Item_id'],
   'Product' => $row['Product'],
    'Brand' => $row['Brand'],
    'Model' => $row['Model']
   );
  array_push($data, $row_data);
 }

 echo json_encode($data);
?>

我的 html 文件应该显示数据:

<html>
<head>

    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/base/jquery-ui.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<!--PQ Grid files-->
    <link rel="stylesheet" href="pqgrid.min.css" />
    <script src="pqgrid.min.js"></script>
<!--PQ Grid Office theme-->
    <link rel="stylesheet" href="themes/office/pqgrid.css" />

<script>
   $(document).ready(function(){
   var url = 'data.php';
      $.getJSON(url, function(data) {
          $.each(data, function(index, data) {
            var obj = { width: 700, height: 400, title: "ParamQuery Grid Example",resizable:true,draggable:true };
        obj.colModel = [{ title: "Id", width: 100, dataType: "integer" },
        { title: "Product", width: 200, dataType: "string" },
        { title: "Brand", width: 150, dataType: "string" },
        { title: "Model", width: 150, dataType: "string"}];
        obj.dataModel = { data:data};
        $("#grid_array").pqGrid(obj);

    });


   });
                    });


</script>
</head>
<body>

 <div id="grid_array" style="margin:100px;">
</div>
</body>

</html>

【问题讨论】:

    标签: php jquery html json


    【解决方案1】:

    也许现在回答已经太晚了,无论如何我发现你没有正确设置 colModel...我的意思是,你忘记将列链接到 "fields"

    即:

    { title: "Product", width: 200, dataType: "string", dataIndx: "Product" }
    

    其中 dataIndx 是 JSON 字段; “title”只是标题,而不是直接的数据绑定......结果你看到的是行但空白

    我有基于 paramgrid 的演示 here

    您可以在 colModel 结构中看到 de dataIndx 字段...

    【讨论】:

    • 您好,欢迎来到 StackOverflow,感谢您的回答!请从答案中删除您的其他问题并为其创建一个单独的问题。
    • 您可以使用“”按钮创建一个新问题。
    • 谢谢 RobAu 和 Tarod... 我已经解决了我的问题,我没有正确执行分配,现在一切正常。我已经更正了答案,我认为这就是这个问题的全部解决方案。我希望这对某些人有用:)
    猜你喜欢
    • 1970-01-01
    • 2014-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多