一个JQuery的分页查询问题
各位高手,我是jQuery EasyUI的初学者,现在使用JQuery EasyUI+Asp.net完成一个表的显示、查询和分页。
目前实现:
(1)页面第一次显示时,可以正常分页、显示,没有问题
(2)用户输入查询条件(起止日期)查询后,查询结果也正确,默认显示第一页,也没有问题;
问题在于:用户在查询结果中切换分页显示时,数据结果集又重新回到了没有查询时的样子。
请各位大侠指点。跪谢。
代码如下:
<script type="text/javascript">
$(function () {
});
function searchLog() {
beginDate = $('#beginDate').datebox('getValue');
endDate = $('#endDate').datebox('getValue');
$.ajax({
type: "get",
url: 'Log_Handler.ashx?action=showAllLog100&beginDate=' + beginDate + '&endDate=' + endDate,
async: false,
dataType: "json",
success: function (data) {
$("#grid_Log").datagrid("loadData", eval(data));
},
error: function (err) {
$.messager.alert('注意', '抱歉,没有查到相关数据', 'error');
}
});
}
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'center',title:'系统日志'" style="margin:20px 0;"></div>
<div id="tb" style="padding:2px 5px;">
日志开始时间: <input class="easyui-datebox" id="beginDate" style="width:110px">
日志结束时间: <input class="easyui-datebox" id="endDate" style="width:110px">
<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="searchLog()">查找</a>
</div>
<table id="grid_Log" class="easyui-datagrid" title="系统日志" style="width:800px;height:650px"
data-options="
method:'get',
url:'Log_Handler.ashx?action=showAllLog100&beginDate=0&endDate=0',
loadmsg:'正在加载中, 请耐心等待......',
iconCls: 'icon-edit',
rownumbers:true,
singleSelect:true,
pagination:true,
pageNumber: 1,
pageSize: 30,
pageList: [30, 50, 70, 90],
collapsible:true">
<thead>
<tr>
<th field="LOG_DATETIME" width="200" align="left">日志时间</th>
<th field="LOG_CONTENT" width="900" align="left">日志内容</th>
<th field="LOG_LEVEL" width="80" align="center">日志级别</th>
</tr>
</thead>
</table>
</body>
后台代码如下:
public class Log_Handler : IHttpHandler
{
public string _strJson = string.Empty; //返回到前端的JSON结果
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string action = context.Request["action"].ToString();
switch (action)
{
case "showAllLog100":
showAllLog100(context);
break;
}
context.Response.Clear();
context.Response.ContentEncoding = Encoding.UTF8;
context.Response.ContentType = "application/json";
context.Response.Write(_strJson);
context.Response.Flush();
context.Response.End();
}
/// <summary>
/// 显示所有日志
/// </summary>
/// <param name="context"></param>
public void showAllLog100(HttpContext context)
{
string sql = string.Empty;
DataTable dt = new DataTable();
int page = Convert.ToInt32(context.Request.Params["page"]);//页索引
int rows = Convert.ToInt32(context.Request.Params["rows"]);
string beginDate = context.Request.Params["beginDate"].ToString();
string endDate = context.Request.Params["endDate"].ToString();
sql = string.Format(@" select * from T_LOG where 1=1 ");
if (beginDate != "0" && endDate != "0")
{
sql = sql + " AND TO_CHAR(LOG_DATETIME, 'yyyy-mm-dd') BETWEEN '"+beginDate +"' AND '"+endDate+"'";
}
sql = sql + " order by LOG_DATETIME desc";
DataAccess_OLEDB.changeTo_MyProjectDB();
dt = DataAccess_OLEDB.GetDataTable(sql);
_strJson = Json4EasyUI.onDataGrid(dt, page, rows);
}
}