我对jQuery和Javascript一般都很陌生,所以我在尝试理解它是如何工作方面遇到了很多麻烦。我正在使用jQgrid来显示SQL Server中运行的数据库中的某些行,我已经能够显示表中的信息并能够按降序或升序排序,甚至可以显示更多记录。 唯一不起作用的是分页和搜索工具,我真的不明白为什么一旦它加载数据就不能理解它,它在本地操作它并且它不需要做对服务器的任何更多请求。会是什么呢?此外,我已经完成了我的研究,并且我已经看到有一个名为'editurl'的变量,我并不真正了解它的目的。
这是我的javascript代码
jQuery(document).ready(function() {
var myGrid = $("#mygrid").jqGrid({
url:'admanagerjson.php',
datatype: 'json',
mtype: 'GET',
colModel: [
{name:'Sucursal', index:'Sucursal', width:20},
{name:'Pedido', index:'Pedido', width:50},
{name:'PedidoAdpro', index:'PedidoAdpro', width:50},
{name:'FechaPedido', index:'FechaPedido', width:80, align:'right'},
{name:'Cancelado', index:'Cancelado', width:20},
{name:'FECHA_ACT', index:'FECHA_ACT', width:80, align:'right'},
{name:'FechaEntrega', index:'FechaEntrega', width:80, align:'right'},
{name:'PorcDesc', index:'PorcDesc', width:50, align:'right'},
{name:'PC', index:'PC', width:50, sortable:false},
{name:'Cliente', index:'Cliente', width:50, align:'right'},
{name:'Nombre', index:'Nombre', width:150, align:'right'},
{name:'ComoPaga', index:'ComoPaga', width:80, align:'right'},
{name:'Articulo', index:'Articulo', width:80, sortable:false},
{name:'Descripcion', index:'Descripcion', width:80, sortable:false},
{name:'logo', index:'logo', width:80, sortable:false},
{name:'linea', index:'linea', width:80, sortable:false},
{name:'TotalArtPsos', index:'TotalArtPsos', width:80, sortable:false},
{name:'PorcDesc', index:'PorcDesc', width:80, sortable:false},
{name:'Cantidad', index:'Precio', width:80, sortable:false},
{name:'Precio', index:'Precio', width:80, sortable:false},
{name:'PComision', index:'PComision', width:80, sortable:false},
{name:'Comision', index:'Comision', width:80, sortable:false},
{name:'Asesor', index:'Asesor', width:80, sortable:false},
{name:'Equipo', index:'Equipo', width:80, sortable:false},
{name:'Refactura', index:'Refactura', width:80, sortable:false},
{name:'quincena', index:'quincena', width:80, sortable:false},
{name:'mes', index:'mes', width:80, sortable:false},
{name:'anio', index:'anio', width:80, sortable:false},
{name:'LineNum', index:'LineNum', width:80, sortable:false},
{name:'SlpCode', index:'SlpCode', width:80, sortable:false},
{name:'codigoLinea', index:'codigoLinea', width:80, sortable:false},
{name:'U_Tipo', index:'U_Tipo', width:80, sortable:false},
{name:'ModeloNegocio', index:'ModeloNegocio', width:80, sortable:false},
{name:'EstatusAsesor', index:'EstatusAsesor', width:80, sortable:false},
{name:'EstatusPedido', index:'EstatusPedido', width:80, sortable:false},
{name:'U_Sucursal', index:'U_Sucursal', width:80, sortable:false}
],
pager: '#mypager',
rowNum: 10,
rowList: [10, 20, 500],
viewrecords: true,
autowidth: true,
sortname: 'Pedido',
sortorder: 'desc'
});
myGrid.jqGrid('navGrid','#mypager',{edit:false,add:false,del:false,search:true});
});`
这是我的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)*/
if(!$sidx) $sidx =1;
// connect to the database
$db = odbc_connect($dsn, $dbuser, $dbpassword) or die("Connection Error: " . odbc_error());
$result = odbc_exec($db, "SELECT COUNT(*) AS count FROM Publi_vwAdmgrPedidos");
$row = odbc_fetch_array($result);
$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)
if($start <0) $start = 0;
$SQL = "SELECT TOP $limit * FROM Publi_vwAdmgrPedidos ORDER BY $sidx $sord";
$result = odbc_exec($db, $SQL) or die("Couldn't execute query.".odbc_error());
$response->page = $page;
$response->total = $total_pages;
$response->records = $count;
$i=0;
while($row = odbc_fetch_array($result)) {
$response->rows[$i]['id']=$row['Pedido'];
$response->rows[$i]['cell']=array($row['Sucursal'],
$row['Pedido'],
$row['PedidoAdpro'],
$row['FechaPedido'],
$row['Cancelado'],
$row['FECHA_ACT'],
$row['FechaEntrega'],
$row['PorcDes'],
$row['PC'],
$row['Cliente'],
$row['Nombre'],
$row['ComoPaga'],
$row['Articulo'],
$row['Descripcion'],
$row['logo'],
$row['linea'],
$row['TotarArtPsos'],
$row['PorcDesc'],
$row['Cantidad'],
$row['Precio'],
$row['PComision'],
$row['Comision'],
$row['Asesor'],
$row['Equipo'],
$row['Refactura'],
$row['quincena'],
$row['mes'],
$row['anio'],
$row['LineNum'],
$row['SlpCode'],
$row['codigoLinea'],
$row['U_Tipo'],
$row['ModeloNegocio'],
$row['EstatusAsesor'],
$row['EstatusPedido'],
$row['U_Sucursal']);
$i++;
}
echo json_encode($response);
?>
答案 0 :(得分:1)
editurl
是您提供的用于执行jqGrid内联编辑功能的创建,更新,删除功能的URL。即,当您在网格上编辑记录时,请求将发送到editurl
进行处理。
您必须在查询中使用$page
varable来获取请求的页面并将其数据作为JSON返回。请记住,对于每个页面,jqGrid都要求服务器返回该页面,但在所有情况下,您只返回第一页。
您的查询可能类似于:
$SQL = "SELECT TOP $limit * FROM
(SELECT ROW_NUMBER() OVER ( ORDER BY $sidx $sord)
as id_column, * FROM Publi_vwAdmgrPedidos)
as table1 where table1.id_column > ($page-1)*$limit ";
免责声明:我没有检查过查询,请确保没有错误。
修改强>
您可以在网址中检查搜索条件中的这些参数。您必须从DB中搜索自己(因为您没有使用本地数据)
searchField
searchString
searchOper