dongyu1983
dongyu1983
2014-06-29 02:04

使用XML在jqgrid中没有数据加载

can you please help me with this inconvenient. I check and check and can't find the answer to this error.

My jqgrid is not loading the information and I dont't know why.

This is my jqgrid code

jQuery().ready(function(){ 
jQuery("#list").jqGrid({
    sortable: true, 
    url: "service.php?username='$active_user'",
    datatype: "xml",
    mtype: "GET",
    colNames: ["ID Donation", "Amount", "Institution", "Country of Institution", "Document ID", "Date"],
    colModel: [
        { name: "id_donation", index:"id_donation",width: 55 },
        { name: "total", index:"total", width: 90 },
        { name: "institution", index:"institution",width: 80, align: "right" },
        { name: "country_institution", index:"country_institution",width: 80, align: "right" },
        { name: "id_personal_doc", index:"id_personal_doc",width: 80, align: "right" },
        { name: "donation_date", index:"donation_date",width: 80, sortable: true }
    ],
    pager: "#pager",
    rowNum: 10,
    rowList: [10, 20, 30],
    sortname: "donation_date",
    rownumbers: true,
    sortorder: "desc",
    viewrecords: true,
    gridview: true,
    caption: "Your past donations",
    height: 230,
    width:800
}); 

And this is my service.php

<?php 
include("Connections/db.php");
$username = $_GET['username'];


$page = $_GET['page']; 

// get how many rows we want to have into the grid - rowNum parameter in the grid 
$limit = $_GET['rows']; 

// get index row - i.e. user click to sort. At first time sortname parameter -
// after that the index from colModel 
$sidx = $_GET['sidx']; 

// sorting order - at first time sortorder 
$sord = $_GET['sord']; 

// if we not pass at first time index use the first column for the index or what you want
if(!$sidx) $sidx =1; 

// connect to the MySQL database server 
$db = mysql_connect($hostname_db, $username_db, $password_db) or die("Connection Error: " . mysql_error()); 

// select the database 
mysql_select_db($database_db) or die("Error connecting to db."); 

// calculate the number of rows for the query. We need this for paging the result 
$result = mysql_query("SELECT COUNT(*) AS count FROM aedonatio01.donation"); 
$row = mysql_fetch_array($result,MYSQL_ASSOC); 
$count = $row['count']; 

// calculate the total pages for the query 
if( $count > 0 && $limit > 0) { 
          $total_pages = ceil($count/$limit); 
} else { 
          $total_pages = 0; 
} 

// if for some reasons the requested page is greater than the total 
// set the requested page to total page 
if ($page > $total_pages) $page=$total_pages;

// calculate the starting position of the rows 
$start = $limit*$page - $limit;

// if for some reasons start position is negative set it to 0 
// typical case is that the user type 0 for the requested page 
if($start <0) $start = 0; 

// the actual query for the grid data 
$SQL = "SELECT id_donation, username, total, institution, country_institution,    id_personal_doc, donation_date FROM aedonatio01.donation WHERE username = $username ORDER BY $sidx $sord LIMIT $start , $limit"; 
$result = mysql_query( $SQL ) or die("Couldn't execute query.".mysql_error()); 

// we should set the appropriate header information. Do not forget this.
if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) { 
header("Content-type: application/xhtml+xml;charset=iso-8859-15"); 
} else { 
header("Content-type: text/xml;charset=iso-8859-15"); 
} 
$et = ">";  
$s = "<?xml version='1.0' encoding='iso-8859-15'?".$et."
";
$s .=  "<rows>";
$s .= "<page>".$page."</page>";
$s .= "<total>".$total_pages."</total>";
$s .= "<records>".$count."</records>";

// be sure to put text data in CDATA
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$s .= "<row id='". $row[id_donation]."'>";            
$s .= "<cell>". $row[id_donation]."</cell>";
$s .= "<cell>". $row[total]."</cell>";
$s .= "<cell>". $row[institution]."</cell>";
$s .= "<cell>". $row[country_institution]."</cell>";
$s .= "<cell>". $row[id_personal_doc]."</cell>";
$s .= "<cell>". $row[donation_date]."</cell>";
$s .= "</row>";
}
$s .= "</rows>"; 

echo $s;
?>

And this is my XML

<rows>
<page/>
<total>0</total>
<records>2</records>
<row id="1ses">
<cell>1ses</cell>
<cell>500</cell>
<cell>Escuela de Desarrollo Cultural</cell>
<cell>El Salvador</cell>
<cell>033316600</cell>
<cell>26/06/2014</cell>
</row>
<row id="334d">
<cell>334d</cell>
<cell>340</cell>
<cell>Casa de la Salud</cell>
<cell>El Salvador</cell>
<cell>033316600</cell>
<cell>15/05/2014</cell>
</row>
</rows>

Any idea why my grid is not loading any data?

Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongliqin6939 dongliqin6939 7年前

    you need to use xml reader

    xmlReader: { repeatitems: false, root:"rows",row:"row" }
    

    see this and this

    点赞 评论 复制链接分享

为你推荐