当结果超过30个项目时,jEasyUI不会呈现

时间:2013-02-15 06:47:15

标签: php ajax json jquery-easyui

请帮我调试下面的代码。这是一个简单的搜索功能,我试图通过jEasyui数据网格显示结果。如果搜索结果低于30项,则可以使用。问题是,如果查询结果超过30匹配,则json文件将完整生成,但数据网格不会呈现。

<?php
$ip =   $_SERVER['REMOTE_ADDR'];
$DBresult = $ip."DBtoJson.json";
unlink($DBresult);

if(isset($_POST['submit'])){



$cat = $_POST['v1'];
$sch = $_POST['v2'];


$username="root";
$password="********";
$database="dbfldp";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
// $query="SELECT * FROM supportticket ORDER BY support_ticket_number ASC";
$query="SELECT * FROM supportticket WHERE ".$cat." REGEXP '".$sch."' ORDER BY support_ticket_number ASC";
$result=mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

$DBresult = $ip."DBtoJson.json";
$fh = fopen($DBresult,'w') or die ("can't open file");

$stringdata = ' {"total":"'.$num.'","rows":[ ';
fwrite($fh, $stringdata);

$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"support_ticket_number");
$f2=mysql_result($result,$i,"date_filed");
$f3=mysql_result($result,$i,"time_filed");
$f4=mysql_result($result,$i,"duration");
$f5=mysql_result($result,$i,"name");
$f6=mysql_result($result,$i,"department");
$f7=mysql_result($result,$i,"markers_error_tag");
$f8=mysql_result($result,$i,"venue");
$f9=mysql_result($result,$i,"racedate");
$f10=mysql_result($result,$i,"racenumber");
$f11=mysql_result($result,$i,"activities_before_occurance");
$f12=mysql_result($result,$i,"running_programs");
$f13=mysql_result($result,$i,"problem_encountered");
$f14=mysql_result($result,$i,"encountered_before");
$f15=mysql_result($result,$i,"support_person_tag");
$f16=mysql_result($result,$i,"support_comment");
$f17=mysql_result($result,$i,"solution");
$f18=mysql_result($result,$i,"resolved");
$f19=mysql_result($result,$i,"watchlist");
if($i<($num - 1)){$comma=",";}
if($i>=($num - 1)){$comma="";}
$stringdata = '
{
"ticketno":"'.$f1.'",
"datefiled":"'.$f2.'",
"timefiled":"'.$f3.'",
"duration":"'.$f4.'",
"name":"'.$f5.'",
"department":"'.$f6.'",
"reportedas":"'.$f7.'",
"racevenue":"'.$f8.'",
"racedate":"'.$f9.'",
"racenumber":"'.$f10.'",
"experiencedwhile":"'.$f11.'",
"runningapps":"'.$f12.'",
"pencountered":"'.$f13.'",
"historical":"'.$f14.'",
"findings":"'.$f15.'",
"supportcomment":"'.$f16.'",
"actioncaken":"'.$f17.'",
"resolved":"'.$f18.'",
"watchlist":"'.$f19.'"
}'.$comma.'
';
fwrite($fh, $stringdata);
$i++;
}

$stringdata = ' ]}';
fwrite ($fh, $stringdata);
fclose($fh);
if (file_exists($DBresult)) {
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Error DB Entries</title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.1/themes/icon.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.1/demo/demo.css">
<script type="text/javascript" src="jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.1/jquery.easyui.min.js"></script>


<script>


    $(function(){
        $('#tt').datagrid({
            url: '<?php echo $DBresult; ?>',
            title: 'Error Reports',
            autoRowHeight: false,
            fitColumns: true,
            width: 'auto',
            rownumbers: true,
            columns:[[
                {field:'ticketno',title:'Ticket Number',align:'center', sortable:'true'},
                {field:'datefiled',title:'Date Filed',align:'center', sortable:'true'},
                {field:'timefiled',title:'Time Filed',align:'center', sortable:'true'},
                {field:'duration',title:'Duration',align:'center', sortable:'true'},
                {field:'name',title:'Name',align:'center', sortable:'true', hidden: 'true'},
                {field:'department',title:'Department',align:'center', sortable:'true'},
                {field:'reportedas',title:'Reported as:',align:'center', sortable:'true'},
                {field:'racevenue',title:'Race Venue',align:'center', sortable:'true'},
                {field:'racedate',title:'Race Date',align:'center', sortable:'true'},
                {field:'racenumber',title:'R.no#',align:'center', sortable:'true'},
                {field:'experiencedwhile',title:'Experienced while marker is:',align:'center', sortable:'true'},
                {field:'runningapps',title:'Running Apps:',align:'center', sortable:'true'},
                {field:'pencountered',title:'Problem Encountered:',align:'center', sortable:'true'},
                {field:'historical',title:'With History?:',align:'center', sortable:'true'},
                {field:'findings',title:'Findings:',align:'center', sortable:'true'},
                {field:'supportcomment',title:'Support Comment',align:'center', sortable:'true'},
                {field:'actioncaken',title:'Action Taken',align:'center', sortable:'true'},
                {field:'resolved',title:'Resolved?',align:'center', sortable:'true'},
                {field:'watchlist',title:'Watchlist?',align:'center', sortable:'true'}
            ]],
            onHeaderContextMenu: function(e, field){
                e.preventDefault();
                if (!$('#tmenu').length){
                    createColumnMenu();
                }
                $('#tmenu').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            }
        });
    });
    function createColumnMenu(){
        var tmenu = $('<div id="tmenu" style="width:100px;"></div>').appendTo('body');
        var fields = $('#tt').datagrid('getColumnFields');
        for(var i=0; i<fields.length; i++){
            $('<div iconCls="icon-ok"/>').html(fields[i]).appendTo(tmenu);
        }
        tmenu.menu({
            onClick: function(item){
                if (item.iconCls=='icon-ok'){
                    $('#tt').datagrid('hideColumn', item.text);
                    tmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-empty'
                    });
                } else {
                    $('#tt').datagrid('showColumn', item.text);
                    tmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-ok'
                    });
                }
            }
        });
    }

</script>
</head>
<body>
<form name="jho" action="<?php echo $_SERVER["PHP_SELF"];?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="v1">
<select class="easyui-combobox" name="v1" style="width:175px;"> 
    <option value="*">Select A Search Category</option> 
    <option value="support_ticket_number">Ticket Number</option> 
    <option value="date_filed">Date Filed</option> 
    <option value="time_filed">Time Filed</option>
    <option value="duration">Duration</option>
    <option value="name">Name</option>
    <option value="department">Department</option>
    <option value="markers_error_tag">Reported As:</option>
    <option value="venue">Venue</option>
    <option value="racedate">Race Date</option>
    <option value="racenumber">Race Number</option>
    <option value="activities_before_occurance">Occured while:</option>
    <option value="running_programs">Running Apps</option>
    <option value="problem_encountered">Problem Encountered</option>
    <option value="encountered_before">With History?</option>
    <option value="support_person_tag">Findings:</option>
    <option value="support_comment">Support Comment</option>
    <option value="solution">Action Taken</option>
    <option value="resolved">Resolved?</option>
    <option value="watchlist">Watchlist?</option>
</select>
<input type="text" name="v2">
<input type="submit" value="Search" name='submit'>
</form>


<div class="demo-info" style="margin-bottom:10px">
    <div class="demo-tip icon-tip"></div>
    <div>Right click the header of datagrid to show context menu.</div>
</div>  
<table id="tt"></table>
</body>
</html>
<?php
}
} 
else
{?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Error DB Entries</title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.1/themes/icon.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.1/demo/demo.css">
<script type="text/javascript" src="jquery-easyui-1.3.1/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.1/jquery.easyui.min.js"></script>
<script>
    $(function(){
        $('#tt').datagrid({
            url: '<?php echo $ip."DBtoJson.json"; ?>',
            title: 'Error Reports',
            width: 'auto',
            fitColumns: true,
            rownumbers: true,
            singleSelect: true,
            autoRowHeight: false,
            columns:[[
                {field:'ticketno',title:'Ticket Number',align:'center', sortable:'true'},
                {field:'datefiled',title:'Date Filed',align:'center', sortable:'true'},
                {field:'timefiled',title:'Time Filed',align:'center', sortable:'true'},
                {field:'duration',title:'Duration',align:'center', sortable:'true'},
                {field:'name',title:'Name',align:'center', sortable:'true'},
                {field:'department',title:'Department',align:'center', sortable:'true'},
                {field:'reportedas',title:'Reported as:',align:'center', sortable:'true'},
                {field:'racevenue',title:'Race Venue',align:'center', sortable:'true'},
                {field:'racedate',title:'Race Date',align:'center', sortable:'true'},
                {field:'racenumber',title:'R.no#',align:'center', sortable:'true'},
                {field:'experiencedwhile',title:'Experienced while marker is:',align:'center', sortable:'true'},
                {field:'runningapps',title:'Running Apps:',align:'center', sortable:'true'},
                {field:'pencountered',title:'Problem Encountered:',align:'center', sortable:'true'},
                {field:'historical',title:'With History?:',align:'center', sortable:'true'},
                {field:'findings',title:'Findings:',align:'center', sortable:'true'},
                {field:'supportcomment',title:'Support Comment',align:'center', sortable:'true'},
                {field:'actioncaken',title:'Action Taken',align:'center', sortable:'true'},
                {field:'resolved',title:'Resolved?',align:'center', sortable:'true'},
                {field:'watchlist',title:'Watchlist?',align:'center', sortable:'true'}
            ]],
            onHeaderContextMenu: function(e, field){
                e.preventDefault();
                if (!$('#tmenu').length){
                    createColumnMenu();
                }
                $('#tmenu').menu('show', {
                    left:e.pageX,
                    top:e.pageY
                });
            }
        });
    });
    function createColumnMenu(){
        var tmenu = $('<div id="tmenu" style="width:100px;"></div>').appendTo('body');
        var fields = $('#tt').datagrid('getColumnFields');
        for(var i=0; i<fields.length; i++){
            $('<div iconCls="icon-ok"/>').html(fields[i]).appendTo(tmenu);
        }
        tmenu.menu({
            onClick: function(item){
                if (item.iconCls=='icon-ok'){
                    $('#tt').datagrid('hideColumn', item.text);
                    tmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-empty'
                    });
                } else {
                    $('#tt').datagrid('showColumn', item.text);
                    tmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-ok'
                    });
                }
            }
        });
    }

          function changeP(pos){  
        $('#tt').datagrid('loadData',[]);  
        $('#tt').datagrid({pagePosition:pos});  
    }  
</script>
</head>
<body>

<form name="jho" action="<?php echo $_SERVER["PHP_SELF"];?>" method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="v1">
<select class="easyui-combobox" name="v1" style="width:175px;">
    <option value="*">Select A Search Category</option>
    <option value="support_ticket_number">Ticket Number</option> 
    <option value="date_filed">Date Filed</option> 
    <option value="time_filed">Time Filed</option>
    <option value="duration">Duration</option>
    <option value="name">Name</option>
    <option value="department">Department</option>
    <option value="markers_error_tag">Reported As:</option>
    <option value="venue">Venue</option>
    <option value="racedate">Race Date</option>
    <option value="racenumber">Race Number</option>
    <option value="activities_before_occurance">Occured while:</option>
    <option value="running_programs">Running Apps</option>
    <option value="problem_encountered">Problem Encountered</option>
    <option value="encountered_before">With History?</option>
    <option value="support_person_tag">Findings:</option>
    <option value="support_comment">Support Comment</option>
    <option value="solution">Action Taken</option>
    <option value="resolved">Resolved?</option>
    <option value="watchlist">Watchlist?</option>
</select>
<input type="text" name="v2">
<input type="submit" value="Search" name='submit'>
</form>

<div class="demo-info" style="margin-bottom:10px">
    <div class="demo-tip icon-tip"></div>
    <div>Right click the header of datagrid to Change column Visibility.</div>
</div>   
<table id="tt"></table>
</body>
</html>
<?php }?>

1 个答案:

答案 0 :(得分:0)

你有没有尝试过分页:

$('#tt').datagrid({
url: '<?php echo $DBresult; ?>',
title: 'Error Reports',
...
pagination:true,
pageSize:50,
...