jqGrid搜索无法正常工作

时间:2011-02-19 05:31:45

标签: php jquery jqgrid

这是我的代码。我的搜索无效,Edit正在显示但未保存到数据库中!我尝试了此网址http://www.trirand.com/jqgridwiki/doku.php?id=wiki%3asinge_searching中的内容。但我无法纠正它。我该如何解决这个问题?

<SCRIPT type="text/javascript">
    $(function(){
        jQuery("#list1").jqGrid({
            url:'school_manager_db.php?q=1',
            datatype: "xml",
            colNames:['ID','Name', 'City', 'Email','Tel NO','Type','Notes'],
            colModel:[
                {name:'id',index:'school_id', width:65,},
                {name:'name',index:'school_name', width:290,editable: true},
                {name:'city',index:'city', width:130,editable: true},
                {name:'email',index:'email', width:130,editable: true, align:"right"},
                {name:'tel',index:'contact', width:130,editable: true, align:"right"},
                {name:'type',index:'type', width:80,editable: true,edittype: 'select',
                align:"right"},
                {name:'note',index:'note', width:150,editable: true, sortable:false}
            ],
            height:480,
            rowNum:10,
            rowList:[40,80,120],
            imgpath: '/images',
            pager: jQuery('#pager1'),
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            caption:'',
            editurl:"someurl.php"
        }).navGrid('#pager1',{
            edit:true,
            add:true,
            del:true
        });
        jQuery("#list1").searchGrid( options );
    });
</SCRIPT>

我的PHP页面,

<?php
    include("db.php");
    $page = $_GET['page']; // Get the requested page.
    $limit = $_GET['rows']; // Get how many rows we want to have into the grid.
    $sidx = $_GET['sidx']; // Get index row - i.e. user click to sort.
    $sord = $_GET['sord']; // Get the direction.

    if (!$sidx) 
        $sidx =1;

    $result = mysql_query("SELECT COUNT(*) AS count FROM school");
    $row = mysql_fetch_array($result,MYSQL_ASSOC);
    $count = $row['count'];

    if( $count >0 )
    {
        $total_pages = ceil($count/$limit);
    }
    else
    {
        $total_pages = 0;
    }

    if ($page > $total_pages) 
        $page=$total_pages;
    $start = $limit*$page - $limit; // Do not put $limit*($page - 1).
    $SQL = "SELECT school_id, school_name,school_bedge,city,contact, email,typ from school ORDER BY $sidx $sord LIMIT $start , $limit";
    $result = mysql_query( $SQL ) or die("Couldn?t execute query.".mysql_error());

    if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") )
    {
        header("Content-type: application/xhtml+xml;charset=utf-8");
    }
    else
    {
        header("Content-type: text/xml;charset=utf-8");
    }
    $et = ">";
    echo "<?xml version='1.0' encoding='utf-8'?$et\n";
    echo "<rows>";
    echo "<page>".$page."</page>";
    echo "<total>".$total_pages."</total>";
    echo "<records>".$count."</records>";

    // Be sure to put text data in CDATA.
    while($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
        echo "<row id='". $row[id]."'>";
        echo "<cell>". $row['school_id']."</cell>";
        echo "<cell>". $row['school_name']."</cell>";
        echo "<cell>".  $row['city']."</cell>";
        echo "<cell>". $row['email']."</cell>";
        echo "<cell>". $row['contact']."</cell>";
        echo "<cell>". $row['typ']."</cell>";
        echo "<cell><![CDATA[". $row[note]."]]></cell>";
        echo "</row>";
    }
    echo "</rows>";
?>

2 个答案:

答案 0 :(得分:1)

问题出在您使用edittype: select的“类型”列中。尝试替换以下代码:

{name:'type',index:'type', width:80,editable: true, search: false, edittype: 'select',
                align:"right"},

答案 1 :(得分:0)

查看执行搜索时发送到服务器的参数,并修改PHP以进行相应的响应。不是PHP专家(我使用jqGrid和Ruby),但它应该是:

if $search="true" {
    if $name {
       $where_clause = "where name = $name"
    }
}

$SQL = "SELECT school_id, school_name,school_bedge,city,contact, email,typ from school  $where_clause ORDER BY $sidx $sord LIMIT $start , $limit";