Combogrid 是一个jQuery插件用于为输入框添加高级自完成功能(auto-complete)。当用户输入的时候,会在输入框的下方面动态显示一个拥有分页功能 的表格(Grid)控件。 通过Ajax请求,然后结果以JSON(或JSONP:用于跨域请求)的数据类型返回。这个插件拥有许多选项可以配置比如:设置交替行的颜色,自动选择相匹配的查询结果, 设置当输入到第几个字符号才激活表格。此外还支持键盘操作。

  涉及到的相关js和css:

  1、jquery-ui-1.10.1.custom.css

  2、jquery-ui-1.10.1.custom.min.js

  3、jquery.ui.combogrid.css

  4、jquery.ui.combogrid.js

前台页面中代码:

  

<script>
$(document).ready(function(){
$( "#project" ).combogrid({
url: '/per/getTeacherList',
debug:true,
colModel: [{'columnName':'person_id','width':'10','label':'person_id'}, {'columnName':'person_name','width':'60','label':'person_name'},{'columnName':'org_name','width':'30','label':'org_name'}],
select: function( event, ui ) {
$( "#project" ).val( ui.item.person_name );
return false;
}
});
});
</script>
<div>
  <div style="float:left"><input size="30" id="project"/></div><br/> <br/>
  <div id="switcher" style="float:right"></div>
</div>

jfinal中getTeacherList方法的代码示例:

public void getTeacherList(){
//学校ID
int bureau_id = 1;
int page = getParaToInt("page");
//每页显示行数
int limit = getParaToInt("rows");
          //查询条件
String searchTerm = getPara("searchTerm");
if(searchTerm==""){
searchTerm = "%";
} else {
searchTerm = "%" + searchTerm + "%";
}
List<Record> person_list = Person.dao.getTeacherList(bureau_id,searchTerm);
//总条数
int count = person_list.size();
//总页数
int total_pages = 0;
if(count > 0) {
if(count%limit == 0){
total_pages = count/limit;
}else{
total_pages = count/limit + 1;
}
}else{
total_pages = 1;
}
if(page > total_pages) {
page = total_pages;
}
//当前页起始行号
int start = limit * page - limit;
List<Record> list = null;
     //查询数据库
if(total_pages != 0) {
list = Person.dao.getTeacherList(bureau_id,searchTerm, start, limit);
} else {
list = Person.dao.getTeacherList(bureau_id,searchTerm);
}
Map<String,Object> map = new HashMap<String, Object>();
map.put("page", page);
map.put("total", total_pages);
map.put("records", count);
List<Object> list2 = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("person_id", list.get(i).get("PERSON_ID"));
map2.put("person_name", list.get(i).get("PERSON_NAME"));
map2.put("org_name", list.get(i).get("ORG_NAME"));
list2.add(map2);
}
map.put("rows", list2);
renderJson(JSON.toJSONString(map)); }

最终返回给前台的JSON格式为:

{"page":1,"records":2,"rows":[{"org_name":"语文组","person_id":20,"person_name":"张三"},{"org_name":"语文组","person_id":21,"person_name":"李四"}],"total":1}

这样自动完成就实现了。

  

最新文章

  1. cocos2d中各种action方法的应用
  2. android基础(五)网络数据解析方法
  3. php namespace用法
  4. [日常训练]常州集训day5
  5. NEFU 504 new Flip Game (高斯消元)
  6. SQL对字符串数组的处理
  7. Bootstrap系列 -- 28. 下拉菜单状态
  8. 管道寄售库存MRKO结算后,冲销问题
  9. 10.27 noip模拟试题
  10. C语言基础学习运算符-赋值运算符
  11. ArrayList-VS-LinkedList
  12. The JSR-133 Cookbook for Compiler Writers(an unofficial guide to implementing the new JMM)
  13. shell awk统计重复个数
  14. Log4J积累
  15. [51nod1197]字符串的数量 V2
  16. Android -传统蓝牙通信聊天
  17. RSA签名验证
  18. [JSTL - fmt] fmt标签格式化日期
  19. ssh采用expect实现自动输入密码登录、拷贝
  20. POJ 2583

热门文章

  1. Hyper-V 虚拟机无法上网的解决方法
  2. Maven实战(一)搭建Nexus伺服器
  3. linux下的几个cd命令
  4. 音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系
  5. linux 查看可执行文件动态链接库相关信息(转)
  6. makefile之伪目标
  7. Oracle之比较NVARCHAR2字符串
  8. 使用Django框架
  9. spring的容器(控制反转、依赖注入)
  10. 爬虫(2)- HTTP和HTTPS 相关知识