jqGrid 过滤功能故障---只显示一页数据

anchorwang 发布于 2014/12/25 11:02
阅读 381
收藏 0
前端js代码如下:


$("#gridTable").jqGrid({
        url:'./QuerySecurityAudit.php',  //请求数据的url地址 
postData: dataArray,
datatype: "json",  //请求的数据类型        
colNames:['Time','Host','SourceMac','SourceIp','SourcePort', 'PublicIp','TargetIp','TargetPort','TargetUrl'], //数据列名称(数组)        
colModel:[ //数据列各参数信息设置
{name:'Time',index:'Time', width:90, align:'center'},            
{name:'Host',index:'Host', width:70,align:'center'},
{name:'SourceIp',index:'SourceIp', width:70,align:'center'},            
{name:'SourcePort',index:'SourcePort', width:30,align:'center',  sorttype:'integer', searchoptions:{sopt:['eq','ne','le','lt','gt','ge']}},         
     
rowNum:10,//'all',
rowList:[10,30,50,100,200], //分页选项,可以下拉选择每页显示记录数  
loadonce:true,
mtype: "GET",
pager: '#gridPager',  //表格数据关联的分页条,html元素   
autowidth:true, //自动匹配宽度
height:"100%", //自动匹配宽度
gridview:true, //加速显示     
viewrecords: true,  //显示总记录数     
multiselect: false,//true,  //可多选,出现多选框     
multiselectWidth: 25, //设置多选列宽度     
sortable:true,  //可以排序     
sortname: 'Host',  //排序字段名     
sortorder: "asc" //排序方式:倒序,本例中设置默认按id倒序排序
});
$("#gridTable").jqGrid('filterToolbar',{searchOperators : true});



后端php代码:


$page = $_GET['page'];
$limit = $_GET['rows'];
$sidx = $_GET['sidx'];
$sord = $_GET['sord'];
$StartTime = $_GET['ST'];
$EndTime = $_GET['ET'];


$conn_string = CONN_STRING;
$dbconn = pg_connect($conn_string);
if (!$dbconn) 
return;
$query = "SELECT     datetime,host,sourceip,sourceport FROM ABC where datetime > '$StartTime' and datetime < '$EndTime'";
$result = pg_query($dbconn, $query) or die('Query failed: ' . pg_last_error());
$RowNum = pg_num_rows($result);//
if( $RowNum >0 )
{
   $total_pages = ceil($RowNum/$limit);
    } 
else 
{
   $total_pages = 0;
    }
    //print_r($RowNum);
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
$end = $start + $limit;
$responce->page = $page;  //当前页 $page        
$responce->total = $total_pages;//$page; //总页数 $total_pages        
$responce->records = $RowNum; //总记录数




$i = 0;
$j = 0;
while ($row = pg_fetch_array($result))
{
   
   if($j >= $start && $j < $end)
{
$responce->rows[$i]['Time'] = $row['datetime'];
$responce->rows[$i]['Host'] = $row['host'];
$responce->rows[$i]['SourceIp'] = $row['sourceip'];
$responce->rows[$i]['SourcePort'] = $row['sourceport'];


$i = $i + 1;
}
$j = $j + 1;
//print_r($row);
}
pg_free_result($result);
pg_close($dbconn);
//print_r($responce);
echo json_encode($responce);
加载中
返回顶部
顶部