【BootStrap】--具有增删改查功能的表格Demo

                <img class="arrow-down" src="https://csdnimg.cn/release/phoenix/images/arrow_triangle _down.jpg" style="display:inline;">
<img class="arrow-up" src="https://csdnimg.cn/release/phoenix/images/arrow_triangle_up.jpg" style="display:none;">
<div class="subItem"> <ul class="subItem_l" id="top_7355084"></ul>
</div>
</label>
</div>
</div>
<div class="bog_copyright">
<p class="copyright_p">
</div>
<div style="clear:both"></div><div style="border:solid 1px #ccc; background:#eee; float:left; min-width:200px;padding:4px 10px;"><p style="text-align:right;margin:0;"><span style="float:left;">目录<a href="https://blog.csdn.net/wangmei4968/article/details/48437175" title="系统根据文章中H1到H6标签自动生成文章目录">(?)</a></span><a href="#" onclick="javascript:return openct(this);" title="展开">[+]</a></p><ol style="display:none;margin-left:14px;padding-left:14px;line-height:160%;"><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t0">前言</a></li><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t1">版本一</a></li><ol><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t2">样式</a></li><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t3">代码</a></li></ol><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t4"></a></li><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t5">版本二</a></li><ol><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t6">样式</a></li><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t7">代码</a></li></ol><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t8">版本三</a></li><ol><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t9">样式 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </a></li><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t10">代码</a></li></ol><li><a href="https://blog.csdn.net/wangmei4968/article/details/48437175#t11">总结</a></li></ol></div><div style="clear:both"></div><div id="article_content" class="article_content csdn-tracking-statistics" data-pid="blog" data-mod="popu_307" data-dsm="post" style="overflow: hidden;">
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/production/htmledit_views-1f9cf0a071.css">
<div class="htmledit_views">

前言

bootstrap的表格样式,有类似EasyUI的表格,也有卡片式表格,放到移动端显示,各有千秋。但是BootStrap自带的表格是没有操作列的,网上的资源不少,但是都是比较单一、零碎,JS、CSS也经常给的不全,自己经过大概一个月左右的时间,把表格封装了一下,希望能分享给大家。

表格封装了3个版本,接下来给大家展示一下样式和代码。

版本一

1. 样式

表格布局:

【BootStrap】--具有增删改查功能的表格Demo

添加:添加一行新的空白代码

【BootStrap】--具有增删改查功能的表格Demo

修改:选中可修改的列,点击需要修改的单元格,即可变成可编辑的状态。

【BootStrap】--具有增删改查功能的表格Demo

2.代码

  1. @using DatatableDemo.Models
  2. @using ITOO.FreshNewReport.ViewModel
  3. @{
  4. Layout = "~/Views/Shared/_Layout.cshtml";
  5. }
  6. <!DOCTYPE html>
  7. <html>
  8. <head>
  9. <title>Bootstrap 实例 - 表格</title>
  10. <link href="../../BootStrap/StuPersonInfo/bootstrap.min.css" rel="stylesheet" />
  11. <script src="../../BootStrap/StuPersonInfo/bootstrap.min.js"></script>
  12. <script src="../../BootStrap/StuPersonInfo/jquery.min.js"></script>
  13. @*表格JS*@
  14. <link href="../../BootStrap/bootstrap-3.3.5-dist/css/bootstrap.css" rel="stylesheet" />
  15. <meta name="viewport" content="width=device-wdith,initia-scale=1.0">
  16. @*动态添加表格*@
  17. <meta charset="utf-8">
  18. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  19. <link href="../../BootStrap/datagrid/css/bootstrap-table.min.css" rel="stylesheet" />
  20. <link href="../../BootStrap/datagrid/css/bootstrap.min.css" rel="stylesheet" />
  21. <script src="../../BootStrap/datagrid/js/jquery.min.js"></script>
  22. <script src="../../BootStrap/datagrid/js/jquery.base64.js"></script>
  23. <script src="../../BootStrap/datagrid/js/bootstrap-table.js"></script>
  24. <script src="../../BootStrap/datagrid/js/bootstrap-table-export.js"></script>
  25. @*添加批量删除*@
  26. <meta charset="utf-8">
  27. <script type="text/javascript" src="../../BootStrap/datagrid/js/jquery.min.js"></script>
  28. <script type="text/javascript">
  29. $(document).ready(function () {
  30. $("#btnDel").click(function () {
  31. $(":checked").parent().parent().fadeOut("show"); //隐藏所有被选中的input元素
  32. //parent() 获得当前匹配元素集合中每个元素的父元素,
  33. })
  34. $("tr").mousemove(function () {
  35. $(this).css("background", "#F0F0F0");  //鼠标经过背景颜色变为灰色
  36. })
  37. $("tr").mouseout(function () {
  38. $(this).css("background", "#fff");  //离开后背景颜色回复白色
  39. })
  40. //全选
  41. $("#checkAll").click(function () {
  42. if ($("#checkAll").attr("checked") == false) {
  43. $("input[name='checkbox']").each(function () {
  44. $(this).attr("checked", true);
  45. });
  46. } else {
  47. $("input[name='checkbox']").each(function () {
  48. $(this).attr("checked", false);
  49. });
  50. }
  51. });
  52. });
  53. </script>
  54. @*添加一行新表格数据*@
  55. <script>
  56. function append() {
  57. var strAppend = '<tr style="background: rgb(255, 255, 255) none repeat scroll 0% 0%;"><td ><input type="checkbox" value="" editable="false" name="checkbox"></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><tr>';
  58. $("#AddFamily tbody ").append(strAppend).editableTableWidget();
  59. }
  60. </script>
  61. @*表格样式CSS*@
  62. <style>
  63. table {
  64. border-collapse: collapse;
  65. border: 1px solid #FFFFFF;
  66. }
  67. table td {
  68. text-align: center;
  69. height: 30px;
  70. font-size: 12px;
  71. line-height: 30px;
  72. border: 1px solid #efecec;
  73. }
  74. </style>
  75. @*添加批量删除*@
  76. <script src="../../JS/TableJs.js"></script>
  77. </head>
  78. <body>
  79. <script src="../../BootStrap/FamilyJS.js"></script>
  80. @*按钮*@
  81. <div class="heading">
  82. @*添加按钮*@
  83. <button id="build" type="button" class="btn  btn-success" data-toggle="modal" data-target="" onclick="append()">
  84. <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加
  85. </button>
  86. @*修改按钮*@
  87. <button id="btnEdit" type="button" class="btn   btn-warning">
  88. <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>修改
  89. </button>
  90. @*删除按钮---无弹出框*@
  91. <button id="btnDel" type="button" class="btn  btn-danger" data-toggle="modal" data-target="#DeleteForm" onclick="">
  92. <span class="glyphicon glyphicon-minus" aria-hidden="true"></span>删除
  93. </button>
  94. </div>
  95. @*表格*@
  96. <div class="widget-content padded clearfix">
  97. <table id="AddFamily" class="table table-bordered table-striped" width="1000px" border="0" cellspacing="0" cellpadding="0" style="margin: 0 auto">
  98. <thead>
  99. <th class="check-header hidden-xs">
  100. <input id="checkAll" name="checkAll" type="checkbox">
  101. <th>姓名</th>
  102. <th>称谓 </th>
  103. <th>年龄 </th>
  104. <th>政治面貌</th>
  105. <th>电话号码 </th>
  106. <th>工作单位</th>
  107. <th>家庭住址</th>
  108. </thead>
  109. <tbody id="mainbody">
  110. @*从数据库读取的数据,遍历ViewModel里面的字段并赋值*@
  111. @foreach (FamilyInfoViewModel enStuFam in ViewData["DataList"] as List<FamilyInfoViewModel>)
  112. {
  113. <tr>
  114. <td>
  115. <input name="checkbox" type="checkbox" id="1">
  116. </td>
  117. <td data-field="Name">@enStuFam.Name </td>
  118. <td data-field="RelationShip">@enStuFam.RelationShip</td>
  119. <td data-field="Age">@enStuFam.Age</td>
  120. <td>@enStuFam.PoliticalStatus</td>
  121. <td>@enStuFam.TelNum </td>
  122. <td>@enStuFam.WorkUnit</td>
  123. <td>@enStuFam.Address </td>
  124. </tr>
  125. }
  126. </tbody>
  127. </table>
  128. </div>
  129. <link href="../../BootStrap/jquery.bdt.css" rel="stylesheet" />
  130. @*创建表格*@
  131. <script>
  132. //绑定编辑、回车事件
  133. $(function () {
  134. //   $('#build').click(build);//实现创建表格
  135. $('#btnEdit').click(edit);
  136. $('#cells, #rows').keyup(function (e) {
  137. if (e.keyCode === 13) {
  138. //添加存入数据库的代码
  139. }
  140. });
  141. });
  142. //将表格转成可编辑的表格
  143. function edit(index) {
  144. //  $('#table').editableTableWidget();--效果是单击编辑按钮后,所有的都可以编辑
  145. // $(":checked").editableTableWidget();
  146. $(":checked").parent().parent().editableTableWidget();//整行的可以编辑
  147. }
  148. //转成可编辑的表格
  149. /*global $, window*/
  150. $.fn.editableTableWidget = function (options) {
  151. 'use strict';
  152. return $(this).each(function () {
  153. var buildDefaultOptions = function () {
  154. var opts = $.extend({}, $.fn.editableTableWidget.defaultOptions);
  155. opts.editor = opts.editor.clone();
  156. return opts;
  157. },
  158. activeOptions = $.extend(buildDefaultOptions(), options),
  159. ARROW_LEFT = 37, ARROW_UP = 38, ARROW_RIGHT = 39, ARROW_DOWN = 40, ENTER = 13, ESC = 27, TAB = 9,
  160. element = $(this),
  161. editor = activeOptions.editor.css('position', 'absolute').hide().appendTo(element.parent()),
  162. active,
  163. showEditor = function (select) {
  164. active = element.find('td:focus');
  165. if (active.length) {
  166. editor.val(active.text())
  167. .removeClass('error')
  168. .show()
  169. .offset(active.offset())
  170. .css(active.css(activeOptions.cloneProperties))
  171. .width(active.width())
  172. .height(active.height())
  173. .focus();
  174. if (select) {
  175. editor.select();
  176. }
  177. }
  178. },
  179. setActiveText = function () {
  180. var text = editor.val(),
  181. evt = $.Event('change'),
  182. originalContent;
  183. if (active.text() === text || editor.hasClass('error')) {
  184. return true;
  185. }
  186. originalContent = active.html();
  187. active.text(text).trigger(evt, text);
  188. if (evt.result === false) {
  189. active.html(originalContent);
  190. }
  191. },
  192. movement = function (element, keycode) {
  193. if (keycode === ARROW_RIGHT) {
  194. return element.next('td');
  195. } else if (keycode === ARROW_LEFT) {
  196. return element.prev('td');
  197. } else if (keycode === ARROW_UP) {
  198. return element.parent().prev().children().eq(element.index());
  199. } else if (keycode === ARROW_DOWN) {
  200. return element.parent().next().children().eq(element.index());
  201. }
  202. return [];
  203. };
  204. editor.blur(function () {
  205. setActiveText();
  206. editor.hide();
  207. }).keydown(function (e) {
  208. if (e.which === ENTER) {
  209. setActiveText();
  210. editor.hide();
  211. active.focus();
  212. e.preventDefault();
  213. e.stopPropagation();
  214. } else if (e.which === ESC) {
  215. editor.val(active.text());
  216. e.preventDefault();
  217. e.stopPropagation();
  218. editor.hide();
  219. active.focus();
  220. } else if (e.which === TAB) {
  221. active.focus();
  222. } else if (this.selectionEnd - this.selectionStart === this.value.length) {
  223. var possibleMove = movement(active, e.which);
  224. if (possibleMove.length > 0) {
  225. possibleMove.focus();
  226. e.preventDefault();
  227. e.stopPropagation();
  228. }
  229. }
  230. })
  231. .on('input paste', function () {
  232. var evt = $.Event('validate');
  233. active.trigger(evt, editor.val());
  234. if (evt.result === false) {
  235. editor.addClass('error');
  236. } else {
  237. editor.removeClass('error');
  238. }
  239. });
  240. element.on('click keypress dblclick', showEditor)
  241. .css('cursor', 'pointer')
  242. .keydown(function (e) {
  243. var prevent = true,
  244. possibleMove = movement($(e.target), e.which);
  245. if (possibleMove.length > 0) {
  246. possibleMove.focus();
  247. } else if (e.which === ENTER) {
  248. showEditor(false);
  249. } else if (e.which === 17 || e.which === 91 || e.which === 93) {
  250. showEditor(true);
  251. prevent = false;
  252. } else {
  253. prevent = false;
  254. }
  255. if (prevent) {
  256. e.stopPropagation();
  257. e.preventDefault();
  258. }
  259. });
  260. element.find('td').prop('tabindex', 1);
  261. $(window).on('resize', function () {
  262. if (editor.is(':visible')) {
  263. editor.offset(active.offset())
  264. .width(active.width())
  265. .height(active.height());
  266. }
  267. });
  268. });
  269. };
  270. $.fn.editableTableWidget.defaultOptions = {
  271. cloneProperties: ['padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right',
  272. 'text-align', 'font', 'font-size', 'font-family', 'font-weight',
  273. 'border', 'border-top', 'border-bottom', 'border-left', 'border-right'],
  274. editor: $('<input>')
  275. };
  276. </script>
  277. </body>
  278. </html>
@using DatatableDemo.Models
@using ITOO.FreshNewReport.ViewModel
@{
Layout = "~/Views/Shared/_Layout.cshtml"; } <!DOCTYPE html> <html>

<head>

<title>Bootstrap 实例 - 表格</title>

<link href="../../BootStrap/StuPersonInfo/bootstrap.min.css" rel="stylesheet" />

<script src="../../BootStrap/StuPersonInfo/bootstrap.min.js"></script>

<script src="../../BootStrap/StuPersonInfo/jquery.min.js"></script>
@*表格JS*@

&lt;link href="../../BootStrap/bootstrap-3.3.5-dist/css/bootstrap.css" rel="stylesheet" /&gt;
&lt;meta name="viewport" content="width=device-wdith,initia-scale=1.0"&gt; @*动态添加表格*@
&lt;meta charset="utf-8"&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
&lt;link href="../../BootStrap/datagrid/css/bootstrap-table.min.css" rel="stylesheet" /&gt;
&lt;link href="../../BootStrap/datagrid/css/bootstrap.min.css" rel="stylesheet" /&gt;
&lt;script src="../../BootStrap/datagrid/js/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="../../BootStrap/datagrid/js/jquery.base64.js"&gt;&lt;/script&gt;
&lt;script src="../../BootStrap/datagrid/js/bootstrap-table.js"&gt;&lt;/script&gt;
&lt;script src="../../BootStrap/datagrid/js/bootstrap-table-export.js"&gt;&lt;/script&gt; @*添加批量删除*@
&lt;meta charset="utf-8"&gt;
&lt;script type="text/javascript" src="../../BootStrap/datagrid/js/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () {
$("#btnDel").click(function () {
$(":checked").parent().parent().fadeOut("show"); //隐藏所有被选中的input元素
//parent() 获得当前匹配元素集合中每个元素的父元素, }) $("tr").mousemove(function () {
$(this).css("background", "#F0F0F0"); //鼠标经过背景颜色变为灰色 })
$("tr").mouseout(function () {
$(this).css("background", "#fff"); //离开后背景颜色回复白色
}) //全选
$("#checkAll").click(function () { if ($("#checkAll").attr("checked") == false) { $("input[name='checkbox']").each(function () {
$(this).attr("checked", true);
});
} else { $("input[name='checkbox']").each(function () {
$(this).attr("checked", false);
});
} });
});
&lt;/script&gt; @*添加一行新表格数据*@
&lt;script&gt;
function append() { var strAppend = '&lt;tr style="background: rgb(255, 255, 255) none repeat scroll 0% 0%;"&gt;&lt;td &gt;&lt;input type="checkbox" value="" editable="false" name="checkbox"&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;tr&gt;'; $("#AddFamily tbody ").append(strAppend).editableTableWidget(); }
&lt;/script&gt; @*表格样式CSS*@
&lt;style&gt;
table {
border-collapse: collapse;
border: 1px solid #FFFFFF;
} table td {
text-align: center;
height: 30px;
font-size: 12px;
line-height: 30px;
border: 1px solid #efecec;
}
&lt;/style&gt; @*添加批量删除*@
&lt;script src="../../JS/TableJs.js"&gt;&lt;/script&gt;

</head>

<body>

&lt;script src="../../BootStrap/FamilyJS.js"&gt;&lt;/script&gt;

@*按钮*@
&lt;div class="heading"&gt; @*添加按钮*@
&lt;button id="build" type="button" class="btn btn-success" data-toggle="modal" data-target="" onclick="append()"&gt;
&lt;span class="glyphicon glyphicon-plus" aria-hidden="true"&gt;&lt;/span&gt;添加
&lt;/button&gt; @*修改按钮*@
&lt;button id="btnEdit" type="button" class="btn btn-warning"&gt;
&lt;span class="glyphicon glyphicon-edit" aria-hidden="true"&gt;&lt;/span&gt;修改
&lt;/button&gt; @*删除按钮---无弹出框*@
&lt;button id="btnDel" type="button" class="btn btn-danger" data-toggle="modal" data-target="#DeleteForm" onclick=""&gt;
&lt;span class="glyphicon glyphicon-minus" aria-hidden="true"&gt;&lt;/span&gt;删除
&lt;/button&gt; &lt;/div&gt; @*表格*@
&lt;div class="widget-content padded clearfix"&gt;
&lt;table id="AddFamily" class="table table-bordered table-striped" width="1000px" border="0" cellspacing="0" cellpadding="0" style="margin: 0 auto"&gt; &lt;thead&gt;
&lt;th class="check-header hidden-xs"&gt;
&lt;input id="checkAll" name="checkAll" type="checkbox"&gt; &lt;th&gt;姓名&lt;/th&gt;
&lt;th&gt;称谓 &lt;/th&gt;
&lt;th&gt;年龄 &lt;/th&gt;
&lt;th&gt;政治面貌&lt;/th&gt;
&lt;th&gt;电话号码 &lt;/th&gt;
&lt;th&gt;工作单位&lt;/th&gt;
&lt;th&gt;家庭住址&lt;/th&gt;
&lt;/thead&gt;
&lt;tbody id="mainbody"&gt;
@*从数据库读取的数据,遍历ViewModel里面的字段并赋值*@
@foreach (FamilyInfoViewModel enStuFam in ViewData["DataList"] as List&lt;FamilyInfoViewModel&gt;)
{
&lt;tr&gt;
&lt;td&gt;
&lt;input name="checkbox" type="checkbox" id="1"&gt;
&lt;/td&gt; &lt;td data-field="Name"&gt;@enStuFam.Name &lt;/td&gt;
&lt;td data-field="RelationShip"&gt;@enStuFam.RelationShip&lt;/td&gt;
&lt;td data-field="Age"&gt;@enStuFam.Age&lt;/td&gt;
&lt;td&gt;@enStuFam.PoliticalStatus&lt;/td&gt;
&lt;td&gt;@enStuFam.TelNum &lt;/td&gt;
&lt;td&gt;@enStuFam.WorkUnit&lt;/td&gt;
&lt;td&gt;@enStuFam.Address &lt;/td&gt; &lt;/tr&gt;
} &lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt; &lt;link href="../../BootStrap/jquery.bdt.css" rel="stylesheet" /&gt; @*创建表格*@
&lt;script&gt; //绑定编辑、回车事件
$(function () {
// $('#build').click(build);//实现创建表格
$('#btnEdit').click(edit); $('#cells, #rows').keyup(function (e) {
if (e.keyCode === 13) {
//添加存入数据库的代码
}
});
}); //将表格转成可编辑的表格
function edit(index) {
// $('#table').editableTableWidget();--效果是单击编辑按钮后,所有的都可以编辑
// $(":checked").editableTableWidget();
$(":checked").parent().parent().editableTableWidget();//整行的可以编辑 } //转成可编辑的表格
/*global $, window*/
$.fn.editableTableWidget = function (options) {
'use strict';
return $(this).each(function () {
var buildDefaultOptions = function () {
var opts = $.extend({}, $.fn.editableTableWidget.defaultOptions);
opts.editor = opts.editor.clone();
return opts;
},
activeOptions = $.extend(buildDefaultOptions(), options),
ARROW_LEFT = 37, ARROW_UP = 38, ARROW_RIGHT = 39, ARROW_DOWN = 40, ENTER = 13, ESC = 27, TAB = 9,
element = $(this),
editor = activeOptions.editor.css('position', 'absolute').hide().appendTo(element.parent()),
active,
showEditor = function (select) {
active = element.find('td:focus');
if (active.length) {
editor.val(active.text())
.removeClass('error')
.show()
.offset(active.offset())
.css(active.css(activeOptions.cloneProperties))
.width(active.width())
.height(active.height())
.focus();
if (select) {
editor.select();
}
}
},
setActiveText = function () {
var text = editor.val(),
evt = $.Event('change'),
originalContent;
if (active.text() === text || editor.hasClass('error')) {
return true;
}
originalContent = active.html();
active.text(text).trigger(evt, text);
if (evt.result === false) {
active.html(originalContent);
}
},
movement = function (element, keycode) {
if (keycode === ARROW_RIGHT) {
return element.next('td');
} else if (keycode === ARROW_LEFT) {
return element.prev('td');
} else if (keycode === ARROW_UP) {
return element.parent().prev().children().eq(element.index());
} else if (keycode === ARROW_DOWN) {
return element.parent().next().children().eq(element.index());
}
return [];
};
editor.blur(function () {
setActiveText();
editor.hide();
}).keydown(function (e) {
if (e.which === ENTER) {
setActiveText();
editor.hide();
active.focus();
e.preventDefault();
e.stopPropagation();
} else if (e.which === ESC) {
editor.val(active.text());
e.preventDefault();
e.stopPropagation();
editor.hide();
active.focus();
} else if (e.which === TAB) {
active.focus();
} else if (this.selectionEnd - this.selectionStart === this.value.length) {
var possibleMove = movement(active, e.which);
if (possibleMove.length &gt; 0) {
possibleMove.focus();
e.preventDefault();
e.stopPropagation();
}
}
})
.on('input paste', function () {
var evt = $.Event('validate');
active.trigger(evt, editor.val());
if (evt.result === false) {
editor.addClass('error');
} else {
editor.removeClass('error');
}
});
element.on('click keypress dblclick', showEditor)
.css('cursor', 'pointer')
.keydown(function (e) {
var prevent = true,
possibleMove = movement($(e.target), e.which);
if (possibleMove.length &gt; 0) {
possibleMove.focus();
} else if (e.which === ENTER) {
showEditor(false);
} else if (e.which === 17 || e.which === 91 || e.which === 93) {
showEditor(true);
prevent = false;
} else {
prevent = false;
}
if (prevent) {
e.stopPropagation();
e.preventDefault();
}
}); element.find('td').prop('tabindex', 1); $(window).on('resize', function () {
if (editor.is(':visible')) {
editor.offset(active.offset())
.width(active.width())
.height(active.height());
}
});
}); };
$.fn.editableTableWidget.defaultOptions = {
cloneProperties: ['padding', 'padding-top', 'padding-bottom', 'padding-left', 'padding-right',
'text-align', 'font', 'font-size', 'font-family', 'font-weight',
'border', 'border-top', 'border-bottom', 'border-left', 'border-right'],
editor: $('&lt;input&gt;')
}; &lt;/script&gt;

</body>

</html>

版本二

1. 样式

布局样式:

【BootStrap】--具有增删改查功能的表格Demo

添加/修改:

【BootStrap】--具有增删改查功能的表格Demo

2. 代码

  1. @using ITOO.FreshNewReport.ViewModel
  2. @{
  3. Layout = null;
  4. }
  5. <html>
  6. <head>
  7. <title>数据表格编辑_大气漂亮的Bootstrap后台管理系统模板Se7en - JS代码网
  8. </title>
  9. <!--<link href="http://fonts.googleapis.com/css?family=Lato:100,300,400,700" media="all" rel="stylesheet" type="text/css" />-->
  10. <link href="../../BootStrap/se7ven/../../BootStrap/se7ven/stylesheets/bootstrap.min.css" media="all" rel="stylesheet" type="text/css" />
  11. <link href="../../BootStrap/se7ven/stylesheets/font-awesome.css" media="all" rel="stylesheet" type="text/css" />
  12. <link href="../../BootStrap/se7ven/stylesheets/se7en-font.css" media="all" rel="stylesheet" type="text/css" />
  13. <link href="../../BootStrap/se7ven/stylesheets/isotope.css" media="all" rel="stylesheet" type="text/css" />
  14. <link href="../../BootStrap/se7ven/stylesheets/jquery.fancybox.css" media="all" rel="stylesheet" type="text/css" />
  15. <link href="../../BootStrap/se7ven/stylesheets/fullcalendar.css" media="all" rel="stylesheet" type="text/css" />
  16. <link href="../../BootStrap/se7ven/stylesheets/wizard.css" media="all" rel="stylesheet" type="text/css" />
  17. <link href="../../BootStrap/se7ven/stylesheets/select2.css" media="all" rel="stylesheet" type="text/css" />
  18. <link href="../../BootStrap/se7ven/stylesheets/morris.css" media="all" rel="stylesheet" type="text/css" />
  19. <link href="../../BootStrap/se7ven/stylesheets/datatables.css" media="all" rel="stylesheet" type="text/css" />
  20. <link href="../../BootStrap/se7ven/stylesheets/datepicker.css" media="all" rel="stylesheet" type="text/css" />
  21. <link href="../../BootStrap/se7ven/stylesheets/timepicker.css" media="all" rel="stylesheet" type="text/css" />
  22. <link href="../../BootStrap/se7ven/stylesheets/colorpicker.css" media="all" rel="stylesheet" type="text/css" />
  23. <link href="../../BootStrap/se7ven/stylesheets/bootstrap-switch.css" media="all" rel="stylesheet" type="text/css" />
  24. <link href="../../BootStrap/se7ven/stylesheets/daterange-picker.css" media="all" rel="stylesheet" type="text/css" />
  25. <link href="../../BootStrap/se7ven/stylesheets/typeahead.css" media="all" rel="stylesheet" type="text/css" />
  26. <link href="../../BootStrap/se7ven/stylesheets/summernote.css" media="all" rel="stylesheet" type="text/css" />
  27. <link href="../../BootStrap/se7ven/stylesheets/pygments.css" media="all" rel="stylesheet" type="text/css" />
  28. <link href="../../BootStrap/se7ven/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />
  29. <link href="../../BootStrap/se7ven/stylesheets/color/green.css" media="all" rel="alternate stylesheet" title="green-theme" type="text/css" />
  30. <link href="../../BootStrap/se7ven/stylesheets/color/orange.css" media="all" rel="alternate stylesheet" title="orange-theme" type="text/css" />
  31. <link href="../../BootStrap/se7ven/stylesheets/color/magenta.css" media="all" rel="alternate stylesheet" title="magenta-theme" type="text/css" />
  32. <link href="../../BootStrap/se7ven/stylesheets/color/gray.css" media="all" rel="alternate stylesheet" title="gray-theme" type="text/css" />
  33. <script src="../../BootStrap/se7ven/javascripts/jquery.min.js" type="text/javascript"></script>
  34. <script src="../../BootStrap/se7ven/javascripts/jquery-ui.js" type="text/javascript"></script>
  35. <script src="../../BootStrap/se7ven/javascripts/bootstrap.min.js" type="text/javascript"></script>
  36. <script src="../../BootStrap/se7ven/javascripts/raphael.min.js" type="text/javascript"></script>
  37. <script src="../../BootStrap/se7ven/javascripts/selectivizr-min.js" type="text/javascript"></script>
  38. <script src="../../BootStrap/se7ven/javascripts/jquery.mousewheel.js" type="text/javascript"></script>
  39. <script src="../../BootStrap/se7ven/javascripts/jquery.vmap.min.js" type="text/javascript"></script>
  40. <script src="../../BootStrap/se7ven/javascripts/jquery.vmap.sampledata.js" type="text/javascript"></script>
  41. <script src="../../BootStrap/se7ven/javascripts/jquery.vmap.world.js" type="text/javascript"></script>
  42. <script src="../../BootStrap/se7ven/javascripts/jquery.bootstrap.wizard.js" type="text/javascript"></script>
  43. <script src="../../BootStrap/se7ven/javascripts/fullcalendar.min.js" type="text/javascript"></script>
  44. <script src="../../BootStrap/se7ven/javascripts/gcal.js" type="text/javascript"></script>
  45. <script src="../../BootStrap/se7ven/javascripts/jquery.dataTables.min.js" type="text/javascript"></script>
  46. <script src="../../BootStrap/se7ven/javascripts/datatable-editable.js" type="text/javascript"></script>
  47. <script src="../../BootStrap/se7ven/javascripts/jquery.easy-pie-chart.js" type="text/javascript"></script>
  48. <script src="../../BootStrap/se7ven/javascripts/excanvas.min.js" type="text/javascript"></script>
  49. <script src="../../BootStrap/se7ven/javascripts/jquery.isotope.min.js" type="text/javascript"></script>
  50. <script src="../../BootStrap/se7ven/javascripts/isotope_extras.js" type="text/javascript"></script>
  51. <script src="../../BootStrap/se7ven/javascripts/modernizr.custom.js" type="text/javascript"></script>
  52. <script src="../../BootStrap/se7ven/javascripts/jquery.fancybox.pack.js" type="text/javascript"></script>
  53. <script src="../../BootStrap/se7ven/javascripts/select2.js" type="text/javascript"></script>
  54. <script src="../../BootStrap/se7ven/javascripts/styleswitcher.js" type="text/javascript"></script>
  55. <script src="../../BootStrap/se7ven/javascripts/wysiwyg.js" type="text/javascript"></script>
  56. <script src="../../BootStrap/se7ven/javascripts/summernote.min.js" type="text/javascript"></script>
  57. <script src="../../BootStrap/se7ven/javascripts/jquery.inputmask.min.js" type="text/javascript"></script>
  58. <script src="../../BootStrap/se7ven/javascripts/jquery.validate.js" type="text/javascript"></script>
  59. <script src="../../BootStrap/se7ven/javascripts/bootstrap-fileupload.js" type="text/javascript"></script>
  60. <script src="../../BootStrap/se7ven/javascripts/bootstrap-datepicker.js" type="text/javascript"></script>
  61. <script src="../../BootStrap/se7ven/javascripts/bootstrap-timepicker.js" type="text/javascript"></script>
  62. <script src="../../BootStrap/se7ven/javascripts/bootstrap-colorpicker.js" type="text/javascript"></script>
  63. <script src="../../BootStrap/se7ven/javascripts/bootstrap-switch.min.js" type="text/javascript"></script>
  64. <script src="../../BootStrap/se7ven/javascripts/typeahead.js" type="text/javascript"></script>
  65. <script src="../../BootStrap/se7ven/javascripts/daterange-picker.js" type="text/javascript"></script>
  66. <script src="../../BootStrap/se7ven/javascripts/date.js" type="text/javascript"></script>
  67. <script src="../../BootStrap/se7ven/javascripts/morris.min.js" type="text/javascript"></script>
  68. <script src="../../BootStrap/se7ven/javascripts/skycons.js" type="text/javascript"></script>
  69. <script src="../../BootStrap/se7ven/javascripts/fitvids.js" type="text/javascript"></script>
  70. <script src="../../BootStrap/se7ven/javascripts/jquery.sparkline.min.js" type="text/javascript"></script>
  71. <script src="../../BootStrap/se7ven/javascripts/main.js" type="text/javascript"></script>
  72. <script src="../../BootStrap/se7ven/javascripts/respond.js" type="text/javascript"></script>
  73. <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
  74. </head>
  75. <body>
  76. <div class="modal-shiftfix">
  77. <div class="container-fluid main-content">
  78. <div class="page-title">
  79. <h1>Editable DataTables
  80. </h1>
  81. </div>
  82. <!-- DataTables Example -->
  83. <div class="row">
  84. <div class="col-lg-12">
  85. <div class="widget-container fluid-height clearfix">
  86. <div class="heading">
  87. <i class="icon-table"></i>DataTable with Sorting<a class="btn btn-sm btn-primary-outline pull-right" href="#" id="add-row"><i class="icon-plus"></i>Add row</a>
  88. </div>
  89. <div class="widget-content padded clearfix">
  90. <table class="table table-bordered table-striped" id="datatable-editable">
  91. <thead>
  92. @*<th class="check-header hidden-xs">
  93. <input id="checkAll" name="checkAll" type="checkbox">*@
  94. <th>姓名</th>
  95. <th>称谓 </th>
  96. <th>年龄 </th>
  97. <th>政治面貌</th>
  98. <th>电话号码 </th>
  99. <th>工作单位</th>
  100. <th class="hidden-xs">家庭住址</th>
  101. <th width="60"></th>
  102. <th width="75"></th>
  103. </thead>
  104. <tbody>
  105. @foreach (FamilyInfoViewModel enStuFam in ViewData["DataList"] as List<FamilyInfoViewModel>)
  106. {
  107. <tr>
  108. @*<td>
  109. <input name="checkbox" type="checkbox" id="1">
  110. </td>*@
  111. <td>@enStuFam.Name </td>
  112. <td>@enStuFam.RelationShip</td>
  113. <td>@enStuFam.Age</td>
  114. <td>@enStuFam.PoliticalStatus</td>
  115. <td>@enStuFam.TelNum </td>
  116. <td>@enStuFam.WorkUnit</td>
  117. <td>@enStuFam.Address </td>
  118. <td>
  119. <a class="edit-row" href="#">Edit</a>
  120. </td>
  121. <td>
  122. <a class="delete-row" href="#">Delete</a>
  123. </td>
  124. </tr>
  125. }
  126. </tbody>
  127. </table>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. <!-- end DataTables Example -->
  133. </div>
  134. </div>
  135. </body>
  136. </html>
@using ITOO.FreshNewReport.ViewModel
@{
Layout = null;
}
<html> <head>

<title>数据表格编辑_大气漂亮的Bootstrap后台管理系统模板Se7en - JS代码网

</title>

<!--<link href="http://fonts.googleapis.com/css?family=Lato:100,300,400,700" media="all" rel="stylesheet" type="text/css" />-->

<link href="../../BootStrap/se7ven/../../BootStrap/se7ven/stylesheets/bootstrap.min.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/font-awesome.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/se7en-font.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/isotope.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/jquery.fancybox.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/fullcalendar.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/wizard.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/select2.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/morris.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/datatables.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/datepicker.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/timepicker.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/colorpicker.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/bootstrap-switch.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/daterange-picker.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/typeahead.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/summernote.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/pygments.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/color/green.css" media="all" rel="alternate stylesheet" title="green-theme" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/color/orange.css" media="all" rel="alternate stylesheet" title="orange-theme" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/color/magenta.css" media="all" rel="alternate stylesheet" title="magenta-theme" type="text/css" />

<link href="../../BootStrap/se7ven/stylesheets/color/gray.css" media="all" rel="alternate stylesheet" title="gray-theme" type="text/css" />

<script src="../../BootStrap/se7ven/javascripts/jquery.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery-ui.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/bootstrap.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/raphael.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/selectivizr-min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.mousewheel.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.vmap.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.vmap.sampledata.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.vmap.world.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.bootstrap.wizard.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/fullcalendar.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/gcal.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.dataTables.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/datatable-editable.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.easy-pie-chart.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/excanvas.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.isotope.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/isotope_extras.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/modernizr.custom.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.fancybox.pack.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/select2.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/styleswitcher.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/wysiwyg.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/summernote.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.inputmask.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.validate.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/bootstrap-fileupload.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/bootstrap-datepicker.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/bootstrap-timepicker.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/bootstrap-colorpicker.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/bootstrap-switch.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/typeahead.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/daterange-picker.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/date.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/morris.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/skycons.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/fitvids.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/jquery.sparkline.min.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/main.js" type="text/javascript"></script>

<script src="../../BootStrap/se7ven/javascripts/respond.js" type="text/javascript"></script>

<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">

</head>

<body>

<div class="modal-shiftfix">

<div class="container-fluid main-content">

<div class="page-title">

<h1>Editable DataTables

</h1>

</div>

<!-- DataTables Example -->

<div class="row">

<div class="col-lg-12">

<div class="widget-container fluid-height clearfix">

<div class="heading">

<i class="icon-table"></i>DataTable with Sorting<a class="btn btn-sm btn-primary-outline pull-right" href="#" id="add-row"><i class="icon-plus"></i>Add row</a>

</div>

<div class="widget-content padded clearfix">

<table class="table table-bordered table-striped" id="datatable-editable">

<thead>

@<th class="check-header hidden-xs">

<input id="checkAll" name="checkAll" type="checkbox">
@

<th>姓名</th>

<th>称谓 </th>

<th>年龄 </th>

<th>政治面貌</th>

<th>电话号码 </th>

<th>工作单位</th>

<th class="hidden-xs">家庭住址</th>

<th width="60"></th>

<th width="75"></th>

</thead>

<tbody>

@foreach (FamilyInfoViewModel enStuFam in ViewData["DataList"] as List<FamilyInfoViewModel>)

{

<tr>

@<td>

<input name="checkbox" type="checkbox" id="1">

</td>
@
                                        &lt;td&gt;@enStuFam.Name &lt;/td&gt;
&lt;td&gt;@enStuFam.RelationShip&lt;/td&gt;
&lt;td&gt;@enStuFam.Age&lt;/td&gt;
&lt;td&gt;@enStuFam.PoliticalStatus&lt;/td&gt;
&lt;td&gt;@enStuFam.TelNum &lt;/td&gt;
&lt;td&gt;@enStuFam.WorkUnit&lt;/td&gt;
&lt;td&gt;@enStuFam.Address &lt;/td&gt;
&lt;td&gt;
&lt;a class="edit-row" href="#"&gt;Edit&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;a class="delete-row" href="#"&gt;Delete&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
}
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;!-- end DataTables Example --&gt;
&lt;/div&gt;
&lt;/div&gt;

</body>

</html>

版本三

1.样式

卡片式表格:

【BootStrap】--具有增删改查功能的表格Demo

添加/修改 弹出一个新页面:

【BootStrap】--具有增删改查功能的表格Demo

2.代码

View代码:

  1. <div class="container-fluid main-content">
  2. <div class="row">
  3. <div class="col-lg-12">
  4. <div class="widget-container fluid-height clearfix">
  5. @*按钮*@
  6. <div class="heading">
  7. @*添加按钮*@
  8. <span class="ui-button">
  9. <a class="btn  btn-success  glyphicon glyphicon-plus" href="../AddEduInfo/AddEduInfo">添加</a>
  10. </span>
  11. @*修改*@
  12. <span class="ui-button">
  13. <a class="btn  btn-warning  glyphicon glyphicon-edit" href="../AddEduInfo/AddEduInfo">修改</a>
  14. </span>
  15. @*删除*@
  16. @* <span class="ui-button" data-target="#myModal" >
  17. <a class="btn  btn-danger  glyphicon glyphicon-minus" >删除</a>
  18. </span>*@
  19. <span>
  20. <button type="button" class="btn btn-danger glyphicon glyphicon-minus" data-toggle="modal" data-target="#myModal">
  21. 删除
  22. </button>
  23. </span>
  24. </div>
  25. <table id="events-table" style="font-size: 15px" class="table" data-toggle="table" data-card-view="true" data-url="/StuPersonInfo/ShowEducation">
  26. <thead>
  27. <tr class="info">
  28. <th data-field="state" data-checkbox="true"></th>
  29. <th data-field="StartDate" data-sortable="true">开始日期</th>
  30. <th data-field="EndDate" data-sortable="true">结束日期</th>
  31. <th data-field="SchoolName" data-sortable="true">毕业学校</th>
  32. <th data-field="TeacherName" data-visible="true">证明教师</th>
  33. @* <th data-field="" data-sortable="true" data-formatter="operateFormatter" data-events="operateEvents">编  辑</th>*@
  34. </tr>
  35. </thead>
  36. </table>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
 <div class="container-fluid main-content">
                                &lt;div class="row"&gt;
&lt;div class="col-lg-12"&gt;
&lt;div class="widget-container fluid-height clearfix"&gt; @*按钮*@
&lt;div class="heading"&gt; @*添加按钮*@
&lt;span class="ui-button"&gt;
&lt;a class="btn btn-success glyphicon glyphicon-plus" href="../AddEduInfo/AddEduInfo"&gt;添加&lt;/a&gt;
&lt;/span&gt; @*修改*@
&lt;span class="ui-button"&gt;
&lt;a class="btn btn-warning glyphicon glyphicon-edit" href="../AddEduInfo/AddEduInfo"&gt;修改&lt;/a&gt;
&lt;/span&gt; @*删除*@
@* &lt;span class="ui-button" data-target="#myModal" &gt;
&lt;a class="btn btn-danger glyphicon glyphicon-minus" &gt;删除&lt;/a&gt;
&lt;/span&gt;*@ &lt;span&gt;
&lt;button type="button" class="btn btn-danger glyphicon glyphicon-minus" data-toggle="modal" data-target="#myModal"&gt;
删除
&lt;/button&gt;
&lt;/span&gt; &lt;/div&gt; &lt;table id="events-table" style="font-size: 15px" class="table" data-toggle="table" data-card-view="true" data-url="/StuPersonInfo/ShowEducation"&gt;
&lt;thead&gt;
&lt;tr class="info"&gt;
&lt;th data-field="state" data-checkbox="true"&gt;&lt;/th&gt;
&lt;th data-field="StartDate" data-sortable="true"&gt;开始日期&lt;/th&gt;
&lt;th data-field="EndDate" data-sortable="true"&gt;结束日期&lt;/th&gt;
&lt;th data-field="SchoolName" data-sortable="true"&gt;毕业学校&lt;/th&gt;
&lt;th data-field="TeacherName" data-visible="true"&gt;证明教师&lt;/th&gt; @* &lt;th data-field="" data-sortable="true" data-formatter="operateFormatter" data-events="operateEvents"&gt;编 辑&lt;/th&gt;*@
&lt;/tr&gt;
&lt;/thead&gt;
&lt;/table&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt; &lt;/div&gt;</pre><br><span style="font-size:14px;">Controller代码:</span>
  1. #region ShowEducation() 显示教育经历 王美 2015年6月5日
  2. /// <summary>
  3. /// 显示教育经历
  4. /// </summary>
  5. /// <returns>教育经历Json</returns>
  6. public JsonResult ShowEducation()
  7. {
  8. //创建WCF接口
  9. IEduInfoService EduServiceShow = ServiceFactory.GetEduInfoService();
  10. //从缓存中获取身份证号
  11. string IdentityCardID = (String)MemcacheHelper.Get("IdentityCardID");
  12. //调用WCF查询方法
  13. List<EduExperienceViewModel> listEduInfo = EduServiceShow.QueryEduInfo(IdentityCardID);
  14. //返回Json串
  15. return Json(listEduInfo, JsonRequestBehavior.AllowGet);
  16. }
  17. #endregion
#region ShowEducation() 显示教育经历 王美 2015年6月5日
/// <summary>
/// 显示教育经历
/// </summary>
/// <returns>教育经历Json</returns>
public JsonResult ShowEducation()
{
//创建WCF接口
IEduInfoService EduServiceShow = ServiceFactory.GetEduInfoService();
//从缓存中获取身份证号
string IdentityCardID = (String)MemcacheHelper.Get("IdentityCardID");
//调用WCF查询方法
List<EduExperienceViewModel> listEduInfo = EduServiceShow.QueryEduInfo(IdentityCardID);
//返回Json串
return Json(listEduInfo, JsonRequestBehavior.AllowGet);
}
#endregion

前两个版本代码资源链接

总结

做表格的过程乐趣无穷,也有过纠结、烦躁。最后绑定数据实现了查询,添加、修改、删除还在完善。慢慢的开始发现,有的时候我们不仅仅要享受过程,更要竭尽全力去争取一个好的结果。加油吧。

                                <li class="next_article">
<span onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian']);location.href='https://blog.csdn.net/wangmei4968/article/details/48439385';">下一篇</span>
<a href="https://blog.csdn.net/wangmei4968/article/details/48439385" onclick="_gaq.push(['_trackEvent','function', 'onclick', 'blog_articles_xiayipian'])">【BootStrap】--登录加载模态框提示</a>
</li>
</ul>
<div style="clear:both; height:10px;"></div>
</div>
上一篇:knockoutjs如何动态加载外部的file作为component中的template数据源


下一篇:不用外部JAR包,自己实现JSP文件上传!