jqgrid中的外部滤波器
我想使用外部过滤器来过滤jqgrid数据。在我的例子中,使用内置过滤器或搜索框会有点奇怪。我有一个应用程序,其中我将有一个表单,它将接受输入并相应地过滤jgrid数据。我已经实现了代码,它成功地为我提供了过滤数据,但没有在jqgrid中实现。我们在定义jqgrid时指定URL,这里我有另一个URL用于提交过滤表单。在这里,jqgrid中过滤数据和显示数据的URL是不同的。那么,如何在jqgrid中显示过滤后的数据呢。我正在用java Hibernate编写代码 这是“我的过滤器”对话框代码: { 现在,当用户点击“过滤事务”按钮时,我希望重新加载网格。在这里,如果用户选择每月过滤网格,那么它将以月份作为输入,并相应地重新加载网格 这是我的servlet代码:jqgrid中的外部滤波器,jqgrid,filter,Jqgrid,Filter,我想使用外部过滤器来过滤jqgrid数据。在我的例子中,使用内置过滤器或搜索框会有点奇怪。我有一个应用程序,其中我将有一个表单,它将接受输入并相应地过滤jgrid数据。我已经实现了代码,它成功地为我提供了过滤数据,但没有在jqgrid中实现。我们在定义jqgrid时指定URL,这里我有另一个URL用于提交过滤表单。在这里,jqgrid中过滤数据和显示数据的URL是不同的。那么,如何在jqgrid中显示过滤后的数据呢。我正在用java Hibernate编写代码 这是“我的过滤器”对话框代码: {
if(request.getParameter("action").equals("filter")){
if(login!=null)
{
String query=null;
if("Current_Month".equals(request.getParameter("filter_type")))
{
System.out.println("Current month");
int month=cal.get(Calendar.MONTH)+1;
int year=cal.get(Calendar.YEAR);
System.out.println("Current month is: " +month);
query = "from TransactionDetails where register_id="+hb_id+" and transaction_date>='"+year+"-"+month+"-1' and transaction_date<='"+year+"-"+month+"-31'" ;
System.out.println("Current month query is: " +query);
}
if("Yearly".equals(request.getParameter("filter_type")))
{
System.out.println("Yearly");
int year=Integer.parseInt(request.getParameter("year"));
System.out.println("Entered year is: " +year);
query = "from TransactionDetails where register_id="+hb_id+" and transaction_date>='"+year+"-1-1' and transaction_date<='"+year+"-12-31'" ;
System.out.println("Yearly query is: " +query);
}
if("Monthly".equals(request.getParameter("filter_type")))
{
System.out.println("Monthly");
int month=Integer.parseInt(request.getParameter("month"));
System.out.println("Entered month is: " +month);
int year=cal.get(Calendar.YEAR);
query = "from TransactionDetails where register_id="+hb_id+" and transaction_date>='"+year+"-"+month+"-1' and transaction_date<='"+year+"-"+month+"-31'" ;
System.out.println("Current month query is: " +query);
}
if("Range".equals(request.getParameter("filter_type")))
{
System.out.println("Range");
String from_date=request.getParameter("from");
String[] date = from_date.split("/");
from_date = date[2]+"-"+date[1]+"-"+date[0];
String to_date=request.getParameter("to");
date = to_date.split("/");
to_date = date[2]+"-"+date[1]+"-"+date[0];
System.out.println("Entered range is from " +from_date+" to "+to_date);
query = "from TransactionDetails where register_id="+hb_id+" and transaction_date>='"+from_date+"' and transaction_date<='"+to_date+"'" ;
System.out.println("Current month query is: " +query);
}
if("category".equals(request.getParameter("filter_type")))
{
System.out.println("Category");
String category =request.getParameter("t_filter_category");
System.out.println("Entered category is: "+category);
query = "from TransactionDetails where register_id="+hb_id+" and category='"+category+"'" ;
System.out.println("Current month query is: " +query);
}
我通过数据库获得了正确的输出。但是我不知道如何绑定这些数据,或者说如何在我的jgrid中获取这些数据
这是我的网格
function fillGridOnEvent(){
$("#Transaction_grid").html("<table id=\"transaction_list\"></table><div id=\"page\"></div>");
jQuery("#transaction_list").jqGrid({
url:'http://localhost:8084/HomeBudget/TransactionController?action=show&rid=<%=hb_id%>',
datatype: "xml",
height: 300,
colNames:['ID','Date','Type','Category','Amount','Comments'],
colModel:[
{name:'transaction_id',index:'transaction_id', width:20,sortable:false},
{name:'date',index:'date', width:100,sortable:false},
{name:'type',index:'type', width:100,sortable:false},
{name:'category',index:'category', width:150,sortable:false},
{name:'amount',index:'amount', width:100,sortable:false, formatter: 'number'},
{name:'comments',index:'comments', width:210,sortable:false}
],
paging: true,
rowNum:15,
rowList:[15,30,45],
pager: $("#page"),
loadonce:true,
multiselect: false,
gridview:true,
viewrecords:true,
caption: "Transaction"
}).navGrid('#page',{edit:false,add:false,del:false},{multipleSearch:true, multipleGroup:true, showQuery: true});
}我不确定我是否正确理解你。但是我的解决方案是我有多年使用jqGrid和Java及C的经验 定义为jqGrid数据返回json的servlet/处理程序 参数化servlet实现过滤器 设置新jqGrid参数从表单字段读取参数
$("#" + table).setGridParam({
postData:queryString
});
重新加载jqGrid
$+table.jqGrid.triggerreloadGrid
$("#" + table).setGridParam({
postData:queryString
});