highcharts click事件获取数据传给datagrid ,动态加载数据

点击highcharts的柱子 会触发click事件,并将数据传给后台获取到相应部门下的所有员工信息显示在datagrid

如下:添加在charts的初始化里

[java]  view plain  copy
  1. plotOptions : {  
  2.             series : {  
  3.                 cursor : 'pointer',  
  4.                 events : {  
  5.                     click : function(e) {  
  6.                         var value=e.point.id;  
  7.                         location.href ="user/showTable.shtml?id=" +value;  
  8.                     }  
  9.                 }  
  10.             },  

这里的e.point.id 是我再后台返回json数据时 在jsonobject添加的  ,表明了部门的id编号,这样后台就可以根据id获取该部门下的用户

在后台,json数据里获取到了一些value,会显示上一篇的效果。

[java]  view plain  copy
  1. @RequestMapping(value="/getChartsJson" ,produces = "text/html;charset=UTF-8")  
  2.     @ResponseBody  
  3.     public String getJson() {  
  4.         /* 
  5.         JSONObject params = new JSONObject(); 
  6.         params.put("name", deptService.getDeptname()); 
  7.         params.put("count", userService.getDeptCountList()); 
  8.         */  
  9.         List<Integer> listcount=userService.getDeptCountList();  
  10.         List<String> listname=deptService.getDeptname();  
  11.         List<Integer> listdeptid=deptService.getDeptid();  
  12.           
  13.         JSONArray jsonarray=new JSONArray();  
  14.         for(int i=0;i<listcount.size();i++){  
  15.             JSONObject params = new JSONObject();  
  16.             params.put("name", listname.get(i));  
  17.             params.put("count", listcount.get(i) );  
  18.             params.put("id", listdeptid.get(i) );  
  19.               
  20.             jsonarray.add(i,params );  
  21.         }  
  22.         JSONObject json = new JSONObject();  
  23.         json.put("list", jsonarray);  
  24.         String s=json.toString();  
  25.         return s;  
  26.   
  27.     }  
  28.       

再点击柱子后 会调到后台,目的是将我们获取到该柱子所表示的部门id值传入到要显示datagrid的jsp中(这里传入到了table.jsp中)

[java]  view plain  copy
  1. @RequestMapping("/showTable")  
  2. public ModelAndView showTable(Integer id) throws Exception {   
  3.     ModelAndView mav = new ModelAndView("table");   
  4.     mav.addObject("id", id);  
  5.     return mav;  
  6. }  
table.jsp

[html]  view plain  copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>  
  2. <%  
  3.     String path = request.getContextPath();  
  4.     String basePath = request.getScheme() + "://"  
  5.             + request.getServerName() + ":" + request.getServerPort()  
  6.             + path + "/";  
  7. %>  
  8.   
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  10. <html>  
  11. <head>  
  12. <base href="<%=basePath%>">  
  13.   
  14. <title>员工管理</title>  
  15.   
  16. <meta http-equiv="pragma" content="no-cache">  
  17. <meta http-equiv="cache-control" content="no-cache">  
  18. <meta http-equiv="expires" content="0">  
  19. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  20. <meta http-equiv="description" content="This is my page">  
  21. <!-- 
  22.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  23.     -->  
  24. <script type="text/javascript" src="jquery-easyui-1.4.4/jquery.min.js"></script>  
  25. <script type="text/javascript"  
  26.     src="jquery-easyui-1.4.4/jquery.easyui.min.js"></script>  
  27.   
  28. <script type="text/javascript" src="jquery-form.js"></script>  
  29. <link href="jquery-easyui-1.4.4/themes/default/easyui.css"  
  30.     rel="stylesheet" type="text/css" />  
  31. <link href="jquery-easyui-1.4.4/themes/icon.css" rel="stylesheet"  
  32.     type="text/css" />  
  33.   
  34. <link href="css/userdlg.css" rel="stylesheet" type="text/css" />  
  35.   
  36.   
  37.   
  38. <script type="text/javascript">  
  39. $(function () {  
  40.     $('#dgg').datagrid({  
  41.         // url:"user/showUser.shtml",  
  42.          //url:"user/showPageUser.shtml",  
  43.         url : "user/getUserByDeptno.shtml?id=" + ${id},  
  44.   
  45.         columns : [ [  {  
  46.             field : 'id',  
  47.             title : '编号',  
  48.             align : 'center',  
  49.             width : 60  
  50.         }, {  
  51.             field : 'userName',  
  52.             title : '用户名',  
  53.             align : 'center',  
  54.             width : 60  
  55.         }, {  
  56.             field : 'age',  
  57.             title : '年龄',  
  58.             width : 60,  
  59.             align : 'center'  
  60.         }, {  
  61.             field : 'position',  
  62.             title : '职位',  
  63.             width : 60,  
  64.             align : 'center'  
  65.         }, {  
  66.             field : 'sex',  
  67.             title : '性别',  
  68.             width : 60,  
  69.             align : 'center'  
  70.         }, {  
  71.             field : 'deptno',  
  72.             title : '部门编号',  
  73.             width : 60,  
  74.             height:60,  
  75.             align : 'center'  
  76.         } ] ]  
  77.     });  
  78.     var p = $("#dgg").datagrid("getPager");  
  79.     $(p).pagination({  
  80.         pageSize : 10,// 每页显示的记录条数,默认为10  
  81.         pageList : [ 5, 10, 15 ],// 可以设置每页记录条数的列表  
  82.         beforePageText : '第',// 页数文本框前显示的汉字  
  83.         afterPageText : '页    共 {pages} 页',  
  84.         displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',  
  85.   
  86.     });  
  87.       
  88. });  
  89.   
  90. </script>  
  91. </head>  
  92.   
  93.   
  94.   
  95. <body>  
  96.   
  97.         <table id="dgg" title="部门员工" class="easyui-datagrid"  
  98.             style="width: 90%; height: 80%" fitcolumns="true"   
  99.             pagination="true" rownumbers="true">  
  100.   
  101.         </table>  
  102.       
  103.     <input type="button" value="返回" onclick="javascript:history.go(-1);">  
  104. </body>  
  105. </html>  
datagrid动态加载url,将id传入到后台中

[java]  view plain  copy
  1. @RequestMapping(value = "/getUserByDeptno", produces = "text/html;charset=UTF-8")  
  2. @ResponseBody  
  3. public String getUserByDeptno(HttpServletResponse response,  
  4.         @RequestParam(required = false, defaultValue = "10") Integer rows,  
  5.         @RequestParam(required = false, defaultValue = "1") Integer page,  
  6.         @RequestParam(value = "id") Integer id) {  
  7.     // response.setContentType("application/json; charset=utf-8");  
  8.     // response.setContentType("text/json");  
  9.     // response.setCharacterEncoding("UTF-8");  
  10.     JSONObject params = new JSONObject();  
  11.     params.put("pageIndex", (page - 1) * rows);  
  12.     params.put("pageSize", rows);  
  13.     params.put("id", id);  
  14.     List<User> user = userService.getUserByDeptno(params);  
  15.     JSONArray jsonArray = JSONArray.fromObject(user);  
  16.     JSONObject user_json = new JSONObject();  
  17.     user_json.put("total", userService.getCountByDeptno(id));  
  18.     user_json.put("rows", jsonArray);  
  19.     String s = user_json.toString();  
  20.     return s;  
  21.   
  22. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值