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

bootstraptable 下载地址:http://download.csdn.net/detail/csdnrenkly/9674863

                                             文档地址:http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/


前言

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


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


版本一

1. 样式

表格布局:

【BootStrap】--具有增删改查功能的表格Demo_第1张图片


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

【BootStrap】--具有增删改查功能的表格Demo_第2张图片


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

【BootStrap】--具有增删改查功能的表格Demo_第3张图片

2.代码

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

版本二

1. 样式

布局样式:

【BootStrap】--具有增删改查功能的表格Demo_第4张图片

添加/修改:


2. 代码

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


版本三

1.样式       


卡片式表格:

【BootStrap】--具有增删改查功能的表格Demo_第5张图片

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

【BootStrap】--具有增删改查功能的表格Demo_第6张图片


2.代码

View代码:

[html]  view plain  copy
 
  1. <div class="container-fluid main-content">  
  2.   
  3.                                    <div class="row">  
  4.                                        <div class="col-lg-12">  
  5.                                            <div class="widget-container fluid-height clearfix">  
  6.   
  7.                                                @*按钮*@  
  8.                                                <div class="heading">  
  9.   
  10.   
  11.                                                      @*添加按钮*@  
  12.                                                <span class="ui-button">  
  13.                                                    <a class="btn  btn-success  glyphicon glyphicon-plus" href="../AddEduInfo/AddEduInfo">添加a>  
  14.                                                span>  
  15.   
  16.                                                @*修改*@  
  17.                                                <span class="ui-button">  
  18.                                                    <a class="btn  btn-warning  glyphicon glyphicon-edit" href="../AddEduInfo/AddEduInfo">修改a>  
  19.                                                span>  
  20.   
  21.                                                @*删除*@  
  22.                                                @* <span class="ui-button" data-target="#myModal" >  
  23.                                                    <a class="btn  btn-danger  glyphicon glyphicon-minus" >删除a>  
  24.                                                span>*@  
  25.   
  26.                                                <span>  
  27.                                                    <button type="button" class="btn btn-danger glyphicon glyphicon-minus" data-toggle="modal" data-target="#myModal">  
  28.                                                删除  
  29.                                                    button>  
  30.                                                span>  
  31.   
  32.                                                div>  
  33.   
  34.   
  35.                                                <table id="events-table" style="font-size: 15px" class="table" data-toggle="table" data-card-view="true" data-url="/StuPersonInfo/ShowEducation">  
  36.                                                    <thead>  
  37.                                                        <tr class="info">  
  38.                                                            <th data-field="state" data-checkbox="true">th>  
  39.                                                            <th data-field="StartDate" data-sortable="true">开始日期th>  
  40.                                                            <th data-field="EndDate" data-sortable="true">结束日期th>  
  41.                                                            <th data-field="SchoolName" data-sortable="true">毕业学校th>  
  42.                                                            <th data-field="TeacherName" data-visible="true">证明教师th>  
  43.   
  44.                                                            @* <th data-field="" data-sortable="true" data-formatter="operateFormatter" data-events="operateEvents">编  辑th>*@  
  45.                                                        tr>  
  46.                                                    thead>  
  47.                                                table>  
  48.   
  49.   
  50.   
  51.   
  52.                                            div>  
  53.                                        div>  
  54.                                    div>  
  55.   
  56.                                div>  

Controller代码:

[csharp]  view plain  copy
 
  1. #region ShowEducation() 显示教育经历 王美 2015年6月5日  
  2.         ///   
  3.         /// 显示教育经历  
  4.         ///   
  5.         /// 教育经历Json  
  6.         public JsonResult ShowEducation()  
  7.         {  
  8.             //创建WCF接口  
  9.             IEduInfoService EduServiceShow = ServiceFactory.GetEduInfoService();  
  10.             //从缓存中获取身份证号  
  11.            string IdentityCardID = (String)MemcacheHelper.Get("IdentityCardID");             
  12.             //调用WCF查询方法  
  13.             List listEduInfo = EduServiceShow.QueryEduInfo(IdentityCardID);  
  14.             //返回Json串  
  15.             return Json(listEduInfo, JsonRequestBehavior.AllowGet);  
  16.         }  
  17. #endregion  


前两个版本代码资源链接

你可能感兴趣的:(js相关类)