jsp应用bootstrap表格应用实例
一、初始化表格
<div style="margin-top: 80px;margin-left:45px;margin-right:30px;overflow-x: scroll">
<table id="planMakeTable" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th colspan="15" class="tableHead" style="font-size:28px;color: black" id="tableTitle"></th>
</tr>
<tr>
<th></th>
<th colspan="2">产量</th>
<th colspan="2">电</th>
<th colspan="2">煤气、天然气</th>
<th colspan="2">压缩空气</th>
<th rowspan="2">蒸汽(t)</th>
<th rowspan="2">清水(t)</th>
<th rowspan="2">软化水(t)</th>
<th rowspan="2">氧气(m³)</th>
<th rowspan="2">焦炭(t)</th>
<th rowspan="2">柴油(t)</th>
</tr>
<tr>
<th height="50">单位</th>
<th>量</th>
<th>计量单位</th>
<th>量(kwh×10^4)</th>
<th>单耗(kwh)</th>
<th>量(km³)</th>
<th>单耗(m³)</th>
<th>量(km³)</th>
<th>单耗(m³)</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
二、获取表格数据
setPlanMakeTable(todayYear + '-' + todayMonth);
function setPlanMakeTable(msg) {
document.getElementById("tableTitle").innerHTML = msg.replace('-', '年') + "月份生产单位能源消耗计划"
$.ajax({
type: "get",
dataType: "json",
url: "/energyPlan/getEnergyPlanMakeData",
data: {
dateString: msg.replace('-', ''),
flag: "0"
},
success: function (json) {
$.unblockUI();
$('#planMakeTable').find('tr:gt(2)').remove();//删除之前的数据
var s = '';
for (var i = 0; i < json.length; i++)
s += '<tr>' +
'<td style="white-space:nowrap;text-overflow: ellipsis">' + json[i].companyName + '</td>' +
'<td contenteditable="true" oninput="OnInput_cl ($(this).text(),\'' + json[i].electricID + '\',\'' + json[i].electric_partID + '\',\'' + json[i].coalGasID + '\',\'' + json[i].coalGas_PartID + '\',\'' + json[i].airID + '\',\'' + json[i].air_partID + '\')" ' +
'style="white-space:nowrap;text-overflow: ellipsis" id="' + json[i].outPutID + '">' + json[i].outPut + '</td>' +
'<td style="white-space: nowrap;text-overflow: ellipsis">' + json[i].unitName + '</td>' +
'<td contenteditable="true" oninput="OnInput_part ($(this).text(), \'' + json[i].outPutID + '\',\'' + json[i].electric_partID + '\')" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].electricID + '">' + json[i].electric + '</td>' +
'<td style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].electric_partID + '">' + json[i].electric_part + '</td>' +
'<td contenteditable="true" oninput="OnInput_part ($(this).text(), \'' + json[i].outPutID + '\',\'' + json[i].coalGas_PartID + '\')" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].coalGasID + '">' + json[i].coalGas + '</td>' +
'<td style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].coalGas_PartID + '">' + json[i].coalGas_Part + '</td>' +
'<td contenteditable="true" oninput="OnInput_part ($(this).text(), \'' + json[i].outPutID + '\',\'' + json[i].air_partID + '\')" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].airID + '">' + json[i].air + '</td>' +
'<td style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].air_partID + '">' + json[i].air_part + '</td>' +
'<td contenteditable="true" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].steamID + '">' + json[i].steam + '</td>' +
'<td contenteditable="true" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].waterID + '">' + json[i].water + '</td>' +
'<td contenteditable="true" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].softWaterID + '">' + json[i].softWater + '</td>' +
'<td contenteditable="true" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].oxygenID + '">' + json[i].oxygen + '</td>' +
'<td contenteditable="true" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].cokeID + '">' + json[i].coke + '</td>' +
'<td contenteditable="true" style="white-space: nowrap;text-overflow: ellipsis" id="' + json[i].oilID + '">' + json[i].oil + '</td>' +
'</tr>';
$('#planMakeTable').append(s);
// $('#planMakeTable').editableTableWidget().numericInputExample().find('td:first').focus();
// $('#planMakeTable').editableTableWidget({editor: $('<textarea>')}).numericInputExample().find('td:first').focus();
},
error: function (XMLResponse) {
$.unblockUI();
alert(" 错误信息:" + XMLResponse.responseText);
},
beforeSend: function () {
$.blockUI({
css: {
border: 'none',
padding: '5px',
backgroundColor: '#ffffff',
opacity: .8,
color: '#000000'
},
message: '<h4><img src="plan/images/busy.gif"/> 加载中...</h4>'
});
}
});
}
三、监听表格数据改变
<td contenteditable="true" oninput="OnInput_cl ($(this).text(),\'' + json[i].electricID + '\',\'' +
json[i].electric_partID + '\',\'' + json[i].coalGasID + '\',\'' + json[i].coalGas_PartID + '\',\'' +
json[i].airID + '\',\'' + json[i].air_partID + '\')"
function OnInput_cl(value, eleID, elePartID, gasID, gasPartID, airID, airPartID) {
var eleValue = $('#' + eleID + '').text();
var gasValue = $('#' + gasID + '').text();
var airValue = $('#' + airID + '').text();
$('#' + elePartID + '').text(eleValue * 10000 / value);
$('#' + gasPartID + '').text(gasValue * 10000 / value);
$('#' + airPartID + '').text(airValue * 10000 / value);
}
四、保存表格数据
function savePlanMake() {
// 遍历所有的table数据
var flag = false;
var html = '';
$('#planMakeTable').find('tbody').each(function () {
$(this).find('tr').each(function () {
$(this).find('td').each(function () {
if ($(this).attr("id") != "" && $(this).attr("id") != null && $.trim($(this).text()) != "") {
if (isNaN($(this).text())) {
flag = true;
return false;
}
html += $(this).attr("id") + ',' + $(this).text() + "||";
}
});
});
return false;
});
if (flag == true) {
$.messager.popup("只允许输入数字,请检查!");
return false;
} else {
var time = $('#datetimepicker').val();
var dataString = {
"data": html,
"time": time
};
$.ajax({
url: "/energyPlan/saveEnergyPlanMakeData",
type: "post",
dataType: "text",
contentType: "application/json; charset=utf-8",
data: $.toJSON(dataString),
success: function (msg) {
$.unblockUI();
$(".blockUI").fadeOut("slow");
$.messager.popup("提交成功!");
var time = $('#datetimepicker').val();
setPlanMakeTable(time);
},
error: function (xhr, msg, e) {
$.unblockUI();
$(".blockUI").fadeOut("slow");
alert("提交失败:" + xhr + "," + msg + "," + e);
},
beforeSend: function () {
$.blockUI({message: '<h3>正在提交,请稍候...</h3>'});
}
});
}
}
jsp应用bootstrap表格应用实例的更多相关文章
- Bootstrap 表格 笔记
Bootstrap 表格 Bootstrap 提供了一个清晰的创建表格的布局.下表列出了 Bootstrap 支持的一些表格元素: 标签 描述 <table> 为表格添加基础样式. < ...
- 【原创】bootstrap框架的学习 第七课 -[bootstrap表格]
Bootstrap 表格 标签 描述 <table> 为表格添加基础样式. <thead> 表格标题行的容器元素(<tr>),用来标识表格列. <tbody& ...
- bootstrap简单使用实例
表格实例,包含bootstrap.css 和 2.1.1jquery <!DOCTYPE html> <html> <head> <meta charset= ...
- jQuery动态生成Bootstrap表格
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...
- Bootstrap表格样式(附源码文件)--Bootstrap
1.表格默认样式 <h4>表格默认样式</h4><table><!--默认样式--> <tr><th>序号</th> ...
- Bootstrap -- 表格样式、表单布局
Bootstrap -- 表格样式.表单布局 1. 表格的一些样式 举例: <!DOCTYPE html> <html> <head> <meta http- ...
- bootstrap表格添加按钮、模态框实现
bootstrap表格添加按钮.模态框实现 原创 2017年07月20日 17:35:48 标签: bootstrap 1723 bootstrap表格添加按钮.模态框实现 - 需求: 需要表格后面每 ...
- MySQL+Service+Servlet+Jsp实现Table表格分页展示数据
下面以一个示例讲解如何使用MySQL+Service+Servlet+Jsp实现Table表格分页展示数据: eg:请假管理系统 要求如下: 一.打开首页页面, 访问查询请假记录的 servlet , ...
- Bootstrap表格类名及对应图形
.table:基础表格 不管制作哪种表格都离不开类名“table”.所以大家在使用Bootstrap表格时,千万注意,你的<table>元素中一定不能缺少类名“table”. .table ...
随机推荐
- struts2 package元素配置
package 元素的所有属性及对应功能: Attribute Required Description name yes key to for other packages to reference ...
- 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
- SharePoint 2007 页面定制(一)
转:http://www.nanmu.net/SharePoint-MOSS-WSS-Silverlight/Lists/Posts/Post.aspx?ID=74 本文主要包括以下几方面内容: 1. ...
- poj 3279 Fliptile
题意:一个n * m的棋盘,0或1,每次改变一个格子时同时改变上下左右的格子,问用最少次数将棋盘全变成0的策略. 题解:用二进制压缩第一行更改的状态,之后遍历棋盘,如果当前格子为1则改变下方的格子,记 ...
- 使用selector修改TextView中字体的颜色
selector想必大家都用过了,但是在修改字体的颜色的时候还是要细心. 我们在TextView中设置字体颜色一般使用 android:textColor="@color/red" ...
- 黑盒测试用例设计方法&理论结合实际 -> 等价类划分
一. 概念 等价类划分法是把程序的输入域划分成若干部分(子集),然后从每个部分中选取少数代表性数据作为测试用例.每一类的代表性数据在测试中的作用等价于这一类中的其他值. 二. 等价类划分的应用 等价类 ...
- 【树莓PI】下载机
sudo app-get install ntfs-3g 读写ntfs格式的磁盘 mount -t ntfs /dev/sda4 /mnt/usb -o nls=utf8,umask=0 fdisk ...
- MFC程序运行流程
->进入入口函数_tWinMain() 程序首先进入文件AppModul.cpp,找到_tWinMain()函数运行,调用其中的AfxWinMain()函数. 由于为了支持UNICODE,C运行 ...
- bzoj 2656 [Zjoi2012]数列(sequence)(高精度)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2656 [题意] 计算大数递推式 [思路] 高精度 [代码] #include<c ...
- android学习之activity
Activity 的生命周期 和 J2ME 的 MIDlet 一样,在 android 中,Activity 的生命周期交给系统统一管理.与 MIDlet 不同的是安装在 android 中的所有的 ...