bootstrap-table的使用(6)--从servlet传回jsp页面中,除了total和rows外更多的额值

jsp中的内容

请注意responseHandler: function (res)中的内容。
在下面,先是定义了一个id为calcul的label标签,然后我将通过responseHandler函数,在该标签中显示从servlet中传回来的别的参数。

<label style=" float:bottom;font-size: 13px;padding: 5px 10px 0px 10px;" id="calcul"></label>
<script type="text/javascript">
	var TableInit=function(){
	    var oTableInit = new Object();
	    oTableInit.Init=function(){
			$('#reportTable').bootstrapTable({
				method: 'get',
				url: "<c:url value='/IP_IndexServlet?act="+state+"&&mIP="+mIP+"&&start="+StartSearch+"&&end="+EndSearch+"'/>", //获取数据的Servlet地址
	            queryParams: function queryParams(params) {   //设置查询参数              
	            	var param = {                    
	            		pageNumber: params.pageNumber,                    
	            		pageSize: params.pageSize,                              
	            		};                
	            return param;                            
	            },

				cache: false,
				//height: 750, 
				striped: true,
				pagination: true, 
				silent: true, //以静默方式刷新数据
				toolbar:"#toolbar",
				locale:"zh-US", //表格汉化
				sidePagination: "client",
				pageSize: 10,
				pageNumber:mPage,
				pageList: [10, 14,15, 16, 18,20],
				search: true,
				showColumns: true,
				showRefresh: true,
				showExport: true,
				exportDataType: 'all', 
				clickToSelect: true,
				exportTypes:[ 'excel','xlsx','doc','csv', 'txt', 'sql' ],
                exportOptions:{  
                    //ignoreColumn: [12,14],            //忽略某一列的索引  
                    fileName: '数据导出',              //文件名称设置  
                    worksheetName: 'Sheet1',          //表格工作区名称  
                    tableName: 'IP数据表',  
                    excelstyles: ['background-color', 'color', 'font-size', 'font-weight'],  
                    //onMsoNumberFormat: DoOnMsoNumberFormat  
                },
	            columns : [{
	                field : '序号',
	                title : '序号'
	            }, {
	                field : '类型',
	                title : '类型'
	            }, {
	                field : '品牌',
	                title : '品牌'
	            }, {
	                field : '操作系统',
	                title : '操作系统'
	            }, {
	                field : 'IP地址',
	                title : 'IP地址'
	            }, {
	                field : 'MAC地址',
	                title : 'MAC地址'
	            }, {
	                field : '责任单位',
	                title : '责任单位'
	            }, {
	                field : '责任人',
	                title : '责任人'
	            }, {
	                field : '用户名',
	                title : '用户名'
	            }, {
	                field : '密码',
	                title : '密码'
	            }, {
	                field : '接入地点',
	                title : '接入地点'
	            }, {
	                field : '最后修改时间',
	                title : '最后修改时间'
	            }, {
	                field : '是否分配',
	                title : '是否分配'
	            }, {
	                field : '备注',
	                title : '用途'
	            },{
	            	field: 'operate',
	            	title: '操作',
	            	align: 'center',
	            	events: operateEvents,//给按钮注册事件
	            	formatter: operateFormatter
	            }],
                responseHandler: function (res) {
                    $("#calcul").html("<p>这是第一个参数的值 "+res.mCount+" </p><p>这是第二个参数的值 "+res.mTime+" </p>");
                    return{                            //return bootstrap-table能处理的数据格式
                        "total":res.total,
                        "rows":res.rows
                    }
                },
			});
			//隐藏正在加载
			//$('#reportTable').bootstrapTable('hideLoading');
	    };
	    oTableInit.destroy=function(){
	        $("#reportTable").bootstrapTable('destroy');
	    }
	    return oTableInit;
	}
	var oTable = new TableInit();
	oTable.destroy();
	oTable.Init();
</script>

servlet中的内容

下面是servlet中的内容

			response.setContentType("text/json; charset=utf-8");
			PrintWriter out = response.getWriter();
			JSONArray jsonarray = new JSONArray();  
			try {
			ipd.IP_CreateTable(mIP);
		} catch (SQLException e1) {
			// TODO 自动生成的 catch 块
			e1.printStackTrace();
		}

			//获取全部的IP信息
			Result result=ipd.SelectAll(mIP);

	        for(int i=0;i<result.getRowCount();i++) {
				Map rst=result.getRows()[i];
				JSONObject jsonobj = new JSONObject();
				jsonobj.put("序号", rst.get("序号"));  
				jsonobj.put("类型", rst.get("类型"));  
				jsonobj.put("品牌", rst.get("品牌"));
				jsonobj.put("操作系统", rst.get("操作系统"));  
				jsonobj.put("IP地址", rst.get("IP地址"));
				jsonobj.put("MAC地址", rst.get("MAC地址"));  
				jsonobj.put("责任单位", rst.get("责任单位"));
				jsonobj.put("责任人", rst.get("责任人"));  
				jsonobj.put("用户名", rst.get("用户名"));
				jsonobj.put("密码", rst.get("密码"));  
				jsonobj.put("接入地点", rst.get("接入地点"));
				jsonobj.put("最后修改时间", rst.get("最后修改时间"));  
				jsonobj.put("是否分配", rst.get("是否分配"));
				jsonobj.put("备注", rst.get("备注"));  

				jsonarray.add(jsonobj);
			}
			int length = jsonarray.size();
			int count=0;
			double titHour=0;
			JSONObject jsonobj1 = new JSONObject();
			jsonobj1.put("total", length);
			jsonobj1.put("rows", jsonarray);
			jsonobj1.put("mTime", titHour);//这是将在标签中显示的值1
			jsonobj1.put("mCount", count);//这是将在标签中显示的值2
			out = response.getWriter();
			out.println(jsonobj1);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章