项目作者: xuzijie1995

项目描述 :
The bootstrap-table list which I have designed is Based on bootstrap-table 基于Bootstrap-table的表格列
高级语言:
项目地址: git://github.com/xuzijie1995/Bootstrap-table-List.git
创建时间: 2018-05-14T06:16:25Z
项目社区:https://github.com/xuzijie1995/Bootstrap-table-List

开源协议:MIT License

下载


Bootstrap-table-List For Distribution template
基于bootstrap-table的配送模板表格列

The bootstrap-table list which I have designed is Based on bootstrap-table. (Your Product Manager:’I want it.’)

我设计了一个基于bootstrap-table的表格列,在特定场合会用到它,尤其是产品经理坚持的时候,这次是一个配送模板

For your valuable time
这不是所有人的菜,把你的时间用到需要的地方去吧

This is the special advanced use of Bootstrap-table(It’s more complicated than usual, at least I think :P). The Bootstrap-table basic source code changes are not involved. As long as you use Bootstrap, it is not difficult. And you do not need it for most of your time until your product manager thinks you need it.

这只是我对于Bootstrap-table的特殊使用方法,不涉及源码的改动,只要你用过Bootstrap-table,这肯定不难,只是你未必会想到用它做个我这样的配送模板出来,一般table的配置使用已经满足绝大部分场景,所以这种操作并不是必须的,除非像我这样有需求的并且不得不这么干的时候。

What does it look like
来看看它到底长啥样

Please click the picture.
点击看大图会好点。
图片名称

  • That’s it. Just a little bit changes when you set your bootstrap-table.
  • You may ask ‘Why don’t you set the detailView true’. Of course, the detailView can handle it,but my PM wants that the details should be more intuitive. So I design this.
  • 就是这样,在你设置表格的时候来点小操作
  • 父子表是我首先想到的,只不过,这不能很直观的看到所有表格里面的数据,尽管有方法,但我没有那么做,我不太喜欢那样。所以我在原来表格的设计上再加了一个名称与操作的行

The setting code
代码

First
首先

All of the following must be relied upon. Also, you can search ‘bootstrap-table’ to find js & css files you need

确保你有以下引用,或者你可以搜索’bootstrap-table’文档来明确你所需要的的js与css文件以及如何去使用

  1. + <script src="jquery.min.js"></script>
  2. + <script src="bootstrap.min.js"></script>
  3. + <script src="bootstrap-table.js"></script>
  4. + <-- put your locale files after bootstrap-table.js -->
  5. + <script src="bootstrap-table-zh-CN.js"></script>
  6. + <link rel="stylesheet" href="bootstrap.min.css">
  7. + <link rel="stylesheet" href="bootstrap-table.css">

My setting code
设置代码

  1. <html>
  2. ...
  3. <div class="form-group traTablelist">
  4. </div>
  5. ...
  6. </html>
  1. js/jq in script
  2. var $n=[];
  3. var $id=[];
  4. var $d={};
  5. function addTra($data){
  6. var fragment = document.createDocumentFragment();
  7. for(var i=0;i<$data.length;i++){
  8. var $dd=[];
  9. $n.push($data[i]['shipping_name']);
  10. $id.push($data[i]['shipping_id']);
  11. //My processe data 我的加工数据 start==>
  12. var $m=$data[i]['methods'];
  13. for(var j=0;j<$m.length;j++){
  14. var temp={
  15. shipping_area_name:$m[j]['shipping_area_name'],
  16. is_default:$m[j]['is_default'],
  17. firstNum:$m[j]['config']['firstNum'],
  18. firstFee:$m[j]['config']['firstFee'],
  19. conNum:$m[j]['config']['conNum'],
  20. conFee:$m[j]['config']['conFee'],
  21. }
  22. $dd.push(temp);
  23. }
  24. $d[i]=$dd;
  25. //Processe data 处理数据 ==>end
  26. var $e = document.createElement("table");
  27. fragment.appendChild($e);
  28. }
  29. $(".traTablelist").append(fragment);
  30. //create tables 生成配送表格
  31. $(".traTablelist").find('table').each(function(i,e){
  32. var oTraTable = new TraTableInit($n[i],$d[i],$id[i],e);
  33. oTraTable.Init();
  34. });
  35. //init listener 初始化表格内的修改&删除按钮事件
  36. var oTraButtonInit = new TraButtonInit();
  37. oTraButtonInit.Init();
  38. }
  39. //main ajax 主异步函数
  40. $(function(){
  41. $.ajax({
  42. type: "POST",
  43. url: url,
  44. contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  45. dataType: "json",
  46. success: function(data){
  47. ...
  48. addTra(data.data);
  49. ...
  50. },
  51. error:function(data){
  52. ...
  53. }
  54. });
  55. })
  56. //table setting 配置表格
  57. var TraTableInit = function ($t,$d,$id,$e) {
  58. var oTraTableInit = new Object();
  59. $($e).data("name",$t);
  60. //初始化Table
  61. oTraTableInit.Init = function () {
  62. $($e).bootstrapTable({
  63. url: '',
  64. method: 'post',
  65. contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  66. striped: true,
  67. cache: false,
  68. pagination: false,
  69. sortable: false,
  70. sortOrder: "asc",
  71. queryParams: '',
  72. sidePagination: "client",
  73. pageNumber:1,
  74. pageSize: 100,
  75. pageList: [],
  76. search: false,
  77. strictSearch: false,
  78. showColumns: false,
  79. showRefresh: false,
  80. minimumCountColumns: 2,
  81. clickToSelect: false,
  82. singleSelect: false,
  83. height: '',
  84. uniqueId: '',
  85. showToggle:false,
  86. cardView: false,
  87. detailView: false,
  88. showHeader:true,
  89. columns: [
  90. [{
  91. field: '',
  92. title: '模块名称:'+$t,
  93. align: 'left'
  94. },{
  95. field: '',
  96. title: '<a href="javascript:void(0)" data-id="'+$id+'" data-url="distributionEdit.html" data-index="1400">编辑</a><span style="margin-right:15px"></span>',
  97. align: 'right',
  98. colspan: 4,
  99. }],[{
  100. field: 'shipping_area_name',
  101. title: '配送区域',
  102. formatter:function(value,row,index){
  103. if(empty(value)){ //function empty 0->F 1->T
  104. return '默认';
  105. }else{
  106. return value;
  107. }
  108. }
  109. },{
  110. field: 'firstNum',
  111. title: '首件',
  112. width:100
  113. },{
  114. field: 'firstFee',
  115. title: '首费',
  116. width:100
  117. },{
  118. field: 'conNum',
  119. title: '续件',
  120. width:100
  121. },{
  122. field: 'conFee',
  123. title: '续费',
  124. width:100
  125. }]],
  126. data: $d
  127. });
  128. };
  129. return oTraTableInit;
  130. };
  131. var TraButtonInit = function () {
  132. var oTraButtonInit = new Object();
  133. var postdata = {};
  134. oTraButtonInit.Init = function () {
  135. //Delegated events 委托事件
  136. $("div.traTablelist").on("click","a",function(e){
  137. if(e.target.nodeName.toLowerCase()=='a'){
  138. edit($(this));//funtciont edit ->change <a>'s href 为a标签赋予href值会触发跳转
  139. }
  140. });
  141. };
  142. return oTraButtonInit;
  143. };

Key Optimization 关键优化

  1. jsx document.createDocumentFragment();
    Create a virtual node object, and then only operate ‘append’ once for DOM, reducing backflow.
    创建一个虚拟的节点对象,最后只对DOM操作append一次,减少回流
  2. jsx $.each(); 遍历
  3. jsx$("div.traTablelist").on("click","a",function(e){...});
    Delegated events
    委托事件

Asynchronous data
异步数据

  1. {"data":[
  2. {
  3. "shipping_id":"1",
  4. "shipping_name":"整车模板",
  5. "methods":[
  6. {
  7. "shipping_area_name":"",
  8. "shipping_id":"1",
  9. "parent_ids":"",
  10. "is_default":"1",
  11. "config":
  12. {
  13. "firstNum":"1",
  14. "firstFee":"300.00",
  15. "conNum":"1",
  16. "conFee":"300.00"
  17. }
  18. },
  19. {
  20. "shipping_area_name":"北京,天津,河北,山西,内蒙古,辽宁,上海,江苏,浙江,安徽,江西,山东,河南,湖北,湖南,广东,广西,重庆,四川,贵州,云南,陕西,青海,宁夏回族自治区,",
  21. "shipping_id":"1",
  22. "parent_ids":"",
  23. "is_default":"0",
  24. "config":
  25. {
  26. "firstNum":"1",
  27. "firstFee":"300.00",
  28. "conNum":"1",
  29. "conFee":"300.00"
  30. }
  31. },
  32. {
  33. "shipping_area_name":"吉林,黑龙江,甘肃,",
  34. "shipping_id":"1",
  35. "parent_ids":"",
  36. "is_default":"0",
  37. "config":
  38. {
  39. "firstNum":"1",
  40. "firstFee":"500.00",
  41. "conNum":"1",
  42. "conFee":"500.00"
  43. }
  44. },
  45. {
  46. "shipping_area_name":"西藏,",
  47. "shipping_id":"1",
  48. "parent_ids":"",
  49. "is_default":"0",
  50. "config":
  51. {
  52. "firstNum":"1",
  53. "firstFee":"800.00",
  54. "conNum":"1",
  55. "conFee":"100.00"
  56. }
  57. },
  58. ...
  59. ]
  60. },
  61. ...
  62. ]
  63. }

Extra
额外内容

  • if you are interested in what in the ‘button’ which above the tables in the screenshot
  • 如果你对截图中表格上方的“新增”按钮内容感兴趣的话

    Go Bootstrap-region-selection