我一直在梳理wiki的jqgrid,我似乎無法弄清楚如何改變我的控制器中的邏輯jqgrid搜索。Jqgrid控制器調整搜索
我假設搜索將使用在jqgrid中指定的相同URL。這是我的jqgrid調用的動作邏輯。我使用的是Spring 3.0及其Java控制器。
@RequestMapping(value = "studentjsondata", method = RequestMethod.GET)
public @ResponseBody String studentjsondata(HttpServletRequest httpServletRequest) {
Format formatter = new SimpleDateFormat("MMMM dd, yyyy");
String column = "id";
if(httpServletRequest.getParameter("sidx") != null){
column = httpServletRequest.getParameter("sidx");
}
String orderType = "DESC";
if(httpServletRequest.getParameter("sord") != null){
orderType = httpServletRequest.getParameter("sord").toUpperCase();
}
int page = 1;
if(Integer.parseInt(httpServletRequest.getParameter("page")) >= 1){
page = Integer.parseInt(httpServletRequest.getParameter("page"));
}
int limitAmount = 10;
int limitStart = limitAmount*page - limitAmount;
List<Person> students = Person.findStudentPeopleOrderByColumn(true, column, orderType, limitStart, limitAmount).getResultList();
long countStudents = Student.countStudents();
double tally = Math.ceil(countStudents/10.0d);
int totalPages = (int)tally;
long records = countStudents;
StringBuilder sb = new StringBuilder();
sb.append("{\"page\":\"").append(page).append("\", \"records\":\"").append(records).append("\", \"total\":\"").append(totalPages).append("\", \"rows\":[");
boolean first = true;
for (Person s: students) {
sb.append(first ? "" : ",");
if (first) {
first = false;
}
sb.append(String.format("{\"id\":\"%s\", \"cell\":[\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\"]}",s.getId(), s.getId(), s.getFirstName(), s.getLastName(), formatter.format(s.getDateOfBirth().getTime()), s.getGender(), s.getMaritalStatus()));
}
sb.append("]}");
return sb.toString();
}
,這裏是我的navGrid decleration
$("#studentGrid").jqGrid('navGrid', "#pager", {edit:false,add:false,del:false,search:true},{ },{ },{ },
{
sopt:['eq', 'ne', 'lt', 'gt', 'cn', 'bw', 'ew'],
closeOnEscape: true,
multipleSearch: true,
closeAfterSearch: true
}
);
這是我colModel和colNames
colNames:['id','First Name', 'Last Name', 'Date Of Birth', 'Gender', 'Marital Status'],
colModel:[
{name:'id',index:'id', width:15},
{name:'firstName',index:'firstName', width:30, formoptions:{elmprefix:'(*) '}, editable:true, edittype: 'text', editrules:{required:true}},
{name:'lastName',index:'lastName', width:30, formoptions:{elmprefix:'(*) '}, editable:true, edittype: 'text',editrules:{required:true}},
{name:'dateOfBirth',index:'dateOfBirth', width:30, formoptions:{elmprefix:'(*) '},editrules:{required:true}, editable:true, edittype: 'text',
editoptions: {
dataInit: function(element) {
$(element).datepicker({dateFormat: 'MM dd, yy'})
}
}
},
{name:'gender',index:'gender', width:30, formoptions:{elmprefix:'(*) '}, editable:true, editrules:{required:true}, edittype: 'select',
editoptions:{value:{}}
},
{name:'maritalStatus',index:'maritalStatus', width:30, formoptions:{elmprefix:'(*) '}, editable:true, editrules:{required:true}, edittype: 'select',
editoptions:{value:{}}
}
]
因爲它是,默認情況下搜索使用trhe searchGrid方法。在帖子數組中存在_search: true
和filters: {"groupOp":"AND","rules":[{"field":"firstName","op":"eq","data":"Anil"}]}
。 searchField,searchOper和searchString都是空的,但存在於epost數組中。
我該怎麼做才能使搜索工作?
我是否必須使用json解析器和filters數組將json解析爲Java,然後通過添加where子句並使用Json對象的值來更改我的查詢?
jqgrid查詢自己的數據對象是否回到服務器並啓動新的查詢?
我不太確定我要做什麼,請提供某種形式的指導。
我在代碼中看不到類似'httpServletRequest.getParameter(「filters」)''和'httpServletRequest.getParameter(「_ search」)''的東西。 – Oleg 2012-03-26 14:41:44
我還沒有做出改變,因爲我不確定如何處理這些值。我是否將它作爲arg傳遞給我的查找器,並將其解析爲json形式的java到那裏?我不確定該操作通常使用哪種模式來啓用搜索功能。這些值可以像上面概述的那樣訪問。 – Binaryrespawn 2012-03-26 14:46:48
我已經看到這個頁面http://blog.brzezinka.eu/webmaster-tips/jquery/how-to-enable-the-search-functionality-in-jqgrid它是在PHP中完成的,我在java中做到了這一點?這是通常的做法嗎? – Binaryrespawn 2012-03-26 14:55:58