bootstrap table父子表 子表取不出数据
用bootstrap table做一个父子表 现在子表取不出数据,取数据方法用的和夫表的一样。后台返回的json数据数据也正常,就是前台显示不出
前台代码如下
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; String width=request.getParameter("width"); String height=request.getParameter("height"); %> <!DOCTYPE html> <html> <head> <title>规则冲突</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <!--css样式--> <link href="<%=basePath%>css/bootstrap/bootstrap.min.css" rel="stylesheet"> <link href="<%=basePath%>css/bootstrap/bootstrap-table.css" rel="stylesheet"> <!--js--> <script src="<%=basePath%>js/jquery.min.js" type="text/javascript"></script> <script src="<%=basePath%>js/bootstrap/bootstrap.min.js"></script> <script src="<%=basePath%>js/bootstrap/bootstrap-table.js"></script> <script src="<%=basePath%>js/bootstrap/bootstrap-table-zh-CN.js"></script> </head> <script type='text/javascript'> $(function () { alert("==============="); getSpecialtyName(); //1.初始化Table var oTable = new TableInit(); oTable.Init(); //2.初始化Button的点击事件 /* var oButtonInit = new ButtonInit(); oButtonInit.Init(); */ }); var TableInit = function () { var oTableInit = new Object(); /*初始化Table*/ oTableInit.Init = function () { $('#table').bootstrapTable({ url: '../../ruleConflicts/getTBConPage.do', //请求后台的URL(*) method: 'post', //请求方式(*) toolbar: '#toolbar', //工具按钮用哪个容器 striped: true, //是否显示行间隔色 cache: false, //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*) pagination: true, //是否显示分页(*) sortable: false, //是否启用排序 sortOrder: "asc", //排序方式 queryParamsType : "limit", queryParams: oTableInit.queryParams,//传递参数(*) sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*) pageNumber:1, //初始化加载第一页,默认第一页 pageSize: 25, //每页的记录行数(*) pageList: [10, 25, 50, 100], //可供选择的每页的行数(*) // strictSearch: true, // clickToSelect: true, //是否启用点击选中行 //height: 460, //行高,如果没有设置height属性,表格自动根据记录条数觉得表格高度 // uniqueId: "id", //每一行的唯一标识,一般为主键列 cardView: false, //是否显示详细视图 detailView: true, //是否显示父子表 columns: [{ field: 'tasktitle', title: '工单名称' }, { field: 'networklevel', title: '网络设备级别' }, { field: 'ruleid', title: '规则id' },], onExpandRow: function (index, row, $detail) { oTableInit.InitSubTable(index, row, $detail); } }); }; //得到查询的参数 oTableInit.queryParams = function (params) { var temp = { //这里的键的名字和控制器的变量名必须一直,这边改动,控制器也需要改成一样的 limit: params.limit, //第几条记录 offset: params.offset, specialtyName:$("#specialtyName").val(), countCondition:$("#countCondition").val(), // maxrows: params.limit, // pageindex:params.pageNumber, }; return temp; }; /*子表*/ oTableInit.InitSubTable = function (index, row, $detail) { var cur_table = $detail.html('<table></table>').find('table'); $(cur_table).bootstrapTable({ url: '../../ruleConflicts/getTBConChildrenPage.do', method: 'post', queryParams: { ruleid: row.ruleid }, // ajaxOptions: { ruleid: row.ruleid}, clickToSelect: true, pagination: false, detailView: true,//父子表 // uniqueId: "MENU_ID", dataType:'json', pageSize: 10, pageList: [10, 25], columns: [{ // checkbox: true // }, { field: 'ruleid', title: 'ruleid' }, { field: 'filtername', title: '规则名称' }, { field: 'networkName', title: '网络' }, { field: 'priorityName', title: '优先级' }, { field: 'activation', title: '是否启用' }, { field: 'delay', title: '派单延迟(分)' }, ], //无线循环取子表,直到子表里面没有记录 // onExpandRow: function (index, row, $Subdetail) { // oInit.InitSubTable(index, row, $Subdetail); // } }); }; return oTableInit; }; /*ajax取出专业下拉框的值 */ function getSpecialtyName(){ alert("getspecialtyName----------------------"); $.ajax({ url:'../../ruleConflicts/listSpecialtyName.do', data:{ }, contentType: "application/x-www-form-urlencoded; charset=UTF-8", async: false, dataType:'json', type:'post', success : function(data) { $("#specialtyName option:not(:first)").remove(); $.each(data,function(i, item){ if (item.specialtyName) { $("#specialtyName").append("<option value="+item.specialtyName+">"+item.specialtyName+"</option>"); } }); }, error:function(data){ return; } }); } /*button点击刷新表数据 */ function refresh(){ alert("sbumit!!!!!!!!!"); $('#table').bootstrapTable('refresh', {url: '../../ruleConflicts/getTBConPage.do'}); } </script> <body> <form class="form-horizontal" role="form" action="<%=basePath %>ruleConflicts/getTBConPage.do" method="post" id="search"> <fieldset> <legend>配置数据源</legend> <div class="form-group"> <label class="col-sm-2 control-label" for="ds_host">主机名</label> <div class="col-sm-4"> <select id="countCondition" name="countCondition" class="form-control"> <option value="月">月</option> <option value="周">周</option> </select> </div> <label class="col-sm-1 control-label" for="ds_name">专业</label> <div class="col-sm-4"> <select id="specialtyName" name="specialtyName" class="form-control"> <option value="">请选择</option> </select> </div> </div> <center> <button id="fat-btn" class="btn btn-primary" data-loading-text="Loading..." type="button" onclick="refresh()"> 提交 </button> </center> </fieldset> </form> <fieldset> <table class="table table-striped table-hover" id="table"> <!-- <caption>悬停表格布局</caption> --> <thead> </thead> <tbody> <tr> </tr> </tbody> </table> </fieldset> </body> </html>
@RequestMapping(value = "/getTBConPage.do",method = RequestMethod.POST) public void getTroubleSheetCon(HttpServletRequest request, HttpServletResponse response) throws IOException{ /*获取前端数据*/ //得到客户端传递的页码和每页记录数,并转换成int类型 BufferedReader bufr = new BufferedReader( new InputStreamReader(request.getInputStream(),"UTF-8")); StringBuilder sBuilder = new StringBuilder(""); String temp = ""; while((temp = bufr.readLine()) != null){ sBuilder.append(temp); } bufr.close(); String json = sBuilder.toString(); JSONObject json1 = JSONObject.fromObject(json); String countCondition= json1.getString("countCondition"); String specialtyName= json1.getString("specialtyName"); int pageindex=0; int offset = Integer.parseInt(json1.getString("offset")); int limit = Integer.parseInt(json1.getString("limit")); if(offset !=0){ pageindex = offset/limit; } pageindex+= 1; String specialtySql=""; String condiont_time=""; /*专业*/ if (specialtyName!= null &&!specialtyName.equals("")) { specialtySql=" and t.operationtype = '"+specialtyName+"' "; }else{ specialtySql=""; } /*控制时间周期参数*/ if(countCondition!=null&&countCondition.equals("周")){ condiont_time=" and to_date(t.sendtime, 'yyyy-mm-dd hh24:mi:ss') - "+ " trunc(sysdate) between - 7 and 0"; }else if (countCondition!=null&&countCondition.equals("月")) { condiont_time=" and to_date(t.sendtime, 'yyyy-mm-dd hh24:mi:ss') between "+ " add_months(last_day(sysdate) + 1, -2) and "+ " add_months(last_day(sysdate), -1) "; }else{ condiont_time=""; } String queryString = "select tr.tasktitle, tr.networklevel, tr.ruleid, count(1) "+ " from (select t.tasktitle, "+ " t.operationtype, "+ " t.networklevel, "+ " t.sendtime, "+ " t.ruleId "+ " from troublesheet t "+ " where t.ruleid is not null "+ " and t.ruleid != '清除派单' "+ specialtySql+ condiont_time+") tr"+ " group by tr.tasktitle, tr.networklevel, tr.ruleid "+ " having count(1) > 1"; logger.info("冲突规则查询sql:"+queryString); long start=0l; long end=0l; start =System.currentTimeMillis(); Page page = troubleSheetService.getTroubleSheetConByCondition(queryString, pageindex, limit); end =System.currentTimeMillis(); System.out.println(start-end); List list = new ArrayList(); List<TroubleSheet> _result =new ArrayList(); if (page == null) { list.add(0); list.add(new ArrayList()); } else { list.add(page.getPageInfo().getTotalRowCount()); List<Object[]> _list=page.getData(); for(Object[] obj:_list){ TroubleSheet ts=new TroubleSheet(); ts.setTasktitle(obj[0].toString()); ts.setNetworklevel(obj[1].toString()); ts.setRuleid(obj[2].toString()); _result.add(ts); } list.add(_result); } /*将记录转换成json字符串*/ JSONArray jsonArray=JSONArray.fromObject(_result); /*得到总记录数 */ int total = page.getPageInfo().getTotalRowCount(); JSONObject jsonObject=new JSONObject(); jsonObject.put("rows", jsonArray);//JSONArray jsonObject.put("total",total);//总记录数 request.setCharacterEncoding("utf-8"); //这里不设置编码会有乱码 response.setContentType("text/html;charset=utf-8"); response.setHeader("Cache-Control", "no-cache"); PrintWriter out = response.getWriter(); //输出中文,这一句一定要放到response.setContentType("text/html;charset=utf-8"), response.setHeader("Cache-Control", "no-cache")后面,否则中文返回到页面是乱码 out.print(jsonObject.toString()); out.flush(); out.close(); } @RequestMapping(value = "/getTBConChildrenPage.do",method = RequestMethod.POST) public void searchTroubleSheetCon(HttpServletRequest request, HttpServletResponse response) throws IOException{ BufferedReader bufr = new BufferedReader( new InputStreamReader(request.getInputStream(),"UTF-8")); StringBuilder sBuilder = new StringBuilder(""); String temp = ""; while((temp = bufr.readLine()) != null){ sBuilder.append(temp); } bufr.close(); String json = sBuilder.toString(); JSONObject json1 = JSONObject.fromObject(json); long ruleID= Long.parseLong(json1.getString("ruleid")); FilterRuleView filterRule = new FilterRuleView(); // filterRule.setId(ruleID); filterRule.setId(1073); long start=0l; long end=0l; start =System.currentTimeMillis(); List<FilterRuleView> list= filterRuleService.getFilterRuleById(filterRule, 1, 15); end =System.currentTimeMillis(); System.out.println(start-end); /*将记录转换成json字符串*/ JSONArray jsonArray=JSONArray.fromObject(list); /*得到总记录数 */ int total = 1; PrintWriter out = response.getWriter(); JSONObject jsonObject=new JSONObject(); jsonObject.put("rows", jsonArray);//JSONArray jsonObject.put("total",total);//总记录数 out.print(jsonObject.toString()); out.flush(); out.close(); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
楼主解决了吗?