Browse Source

主子表操作添加通用addColumn方法

RuoYi 4 years ago
parent
commit
35a49e9462

+ 10 - 0
ruoyi-admin/src/main/resources/static/ruoyi/js/common.js

@@ -438,6 +438,16 @@ var sub = {
             return;
         }
         $("#" + table.options.id).bootstrapTable('remove', { field: subColumn, values: ids });
+    },
+    addColumn: function(row, tableId) {
+    	var currentId = $.common.isEmpty(tableId) ? table.options.id : tableId;
+    	table.set(currentId);
+    	var count = $("#" + currentId).bootstrapTable('getData').length;
+    	sub.editColumn();
+    	$("#" + currentId).bootstrapTable('insertRow', {
+            index: count + 1,
+            row: row
+        });
     }
 };
 

+ 8 - 15
ruoyi-admin/src/main/resources/templates/demo/table/subdata.html

@@ -164,22 +164,15 @@
             autoclose: true
         });
         
-        
         function addColumn() {
-        	var count = $("#" + table.options.id).bootstrapTable('getData').length;
-        	sub.editColumn();
-        	
-        	$("#" + table.options.id).bootstrapTable('insertRow', {
-        		index: count,
-                row: {
-                	index: $.table.serialNumber(count),
-                	name: "",
-                	weight: "",
-                	price: "",
-                	date: "",
-                	type: "",
-                }
-        	});
+        	var row = {
+            	name: "",
+            	weight: "",
+            	price: "",
+            	date: "",
+            	type: "",
+            }
+        	sub.addColumn(row);
         }
         
         $("#bootstrap-table").on("post-body.bs.table", function (e, args) {