一、初始化表格

<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表格应用实例的更多相关文章

  1. Bootstrap 表格 笔记

    Bootstrap 表格 Bootstrap 提供了一个清晰的创建表格的布局.下表列出了 Bootstrap 支持的一些表格元素: 标签 描述 <table> 为表格添加基础样式. < ...

  2. 【原创】bootstrap框架的学习 第七课 -[bootstrap表格]

    Bootstrap 表格 标签 描述 <table> 为表格添加基础样式. <thead> 表格标题行的容器元素(<tr>),用来标识表格列. <tbody& ...

  3. bootstrap简单使用实例

    表格实例,包含bootstrap.css 和 2.1.1jquery <!DOCTYPE html> <html> <head> <meta charset= ...

  4. jQuery动态生成Bootstrap表格

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  5. Bootstrap表格样式(附源码文件)--Bootstrap

    1.表格默认样式 <h4>表格默认样式</h4><table><!--默认样式--> <tr><th>序号</th> ...

  6. Bootstrap -- 表格样式、表单布局

    Bootstrap -- 表格样式.表单布局 1. 表格的一些样式 举例: <!DOCTYPE html> <html> <head> <meta http- ...

  7. bootstrap表格添加按钮、模态框实现

    bootstrap表格添加按钮.模态框实现 原创 2017年07月20日 17:35:48 标签: bootstrap 1723 bootstrap表格添加按钮.模态框实现 - 需求: 需要表格后面每 ...

  8. MySQL+Service+Servlet+Jsp实现Table表格分页展示数据

    下面以一个示例讲解如何使用MySQL+Service+Servlet+Jsp实现Table表格分页展示数据: eg:请假管理系统 要求如下: 一.打开首页页面, 访问查询请假记录的 servlet , ...

  9. Bootstrap表格类名及对应图形

    .table:基础表格 不管制作哪种表格都离不开类名“table”.所以大家在使用Bootstrap表格时,千万注意,你的<table>元素中一定不能缺少类名“table”. .table ...

随机推荐

  1. c++编写webui内核 .

    http://blog.csdn.net/sx1989827/article/details/8068779 #pragma once #include <mshtmhst.h> #inc ...

  2. 【HDOJ】4366 Successor

    基本思路是将树形结构转换为线性结构.然后,所求即为一个区间内大于abi的最大的loy指向的ID.将结点按照abi降序排序,注意abi可能相等.然后,使用线段树单点更新,区间查询可解. /* 4366 ...

  3. ORACLE和SQL SERVER的数据同步常用方法

    ORACLE和SQL SERVER的数据同步常用方法 1. 自己编程,或者第三方工具2. 在sqlserver中,使用linkedserver,访问oracle,然后编写job进行数据同步3. 在or ...

  4. Python:urllib和urllib2的区别

    urllib和urllib2都是处理url请求的两个模块,但是相互之间存在不同,不能相互取代 urllib2可以接受一个Reuqest类的实例来设置URL请求的headers,urllib仅可以接受U ...

  5. string evaluated instead to freemarker.template.SimpleScalar

    [2015-09-06 09:07:32.879] ERROR [6B68DD09CE6FECFE20936CA3C6D560AD:http-bio-8087-exec-8] o.a.s.v.free ...

  6. bzoj1098 1301

    这两题很类似,都是在补图上搜索 但是由于补图太大我们不能建出来 考虑先从一个点搜,每次搜可以搜的点, 然后维护一个链表,记录当前还没有搜过的点,搜过之后从链表中删除即可 type node=recor ...

  7. WinCE发展史

    Windows CE概述 WindowsCE是微软公司嵌入式.移动计算平台的基础,它是一个开放的.可升级的32位嵌入式操作系统,是基于掌上型电脑类的电子设备操作系统,它是精简的Windows 95,W ...

  8. python20151130

    tab和空格混排是报错的 import os #如何获取当前路径 #当前路径可以用'.'表示,再用os.path.abspath()将其转换为绝对路径 print(os.path.abspath('. ...

  9. Linux中的设备文件与设备号

    设备文件与设备号   在Linux下,一切皆文件,设备也不例外,为了管理这些设备,系统为它们各自都编了号,而每个设备号又分为主设备号和次设备号.主设备号用来区分不同类型的设备,而次设备号用来区分同一类 ...

  10. J2EE的若干问题

    1.问题:jsp中out.println页面显示不出换行效果.例如: out.println("唱歌"); out.println("跳舞"); 以上代码的结果 ...