Browse Source

Fix tree-column and treegrid extensions

zhixin 7 years ago
parent
commit
40c03909dc
2 changed files with 14 additions and 7 deletions
  1. 12 5
      src/bootstrap-table.js
  2. 2 2
      src/extensions/tree-column/bootstrap-table-tree-column.js

+ 12 - 5
src/bootstrap-table.js

@@ -1632,7 +1632,7 @@
       return false
     }
 
-    initRow (item, i, data) {
+    initRow (item, i, data, parentDom) {
       let key
       const html = []
       let style = {}
@@ -1847,19 +1847,26 @@
         this.pageTo = data.length
       }
 
-      const html = []
+      const trFragments = $(document.createDocumentFragment())
+      let hasTr = false
+
       for (let i = this.pageFrom - 1; i < this.pageTo; i++) {
-        html.push(this.initRow(data[i], i, data))
+        const item = data[i]
+        const tr = this.initRow(item, i, data, trFragments)
+        hasTr = hasTr || !!tr
+        if (tr && typeof tr === 'string') {
+            trFragments.append(tr)
+        }
       }
 
       // show no records
-      if (!html.length) {
+      if (!hasTr) {
         this.$body.html(`<tr class="no-records-found">${Utils.sprintf('<td colspan="%s">%s</td>',
           this.$header.find('th').length,
           this.options.formatNoMatches())}</tr>`)
       }
 
-      this.$body.html(html.join(''))
+      this.$body.html(trFragments)
 
       if (!fixedScroll) {
         this.scrollTo(0)

+ 2 - 2
src/extensions/tree-column/bootstrap-table-tree-column.js

@@ -76,7 +76,7 @@
                     if (that.header.classes[i]) {
                         _class.push(that.header.classes[i].split('"')[1] || '');
                     }
-                    that.header.classes[i] = 'class="' + _class.join(' ') + '"';
+                    that.header.classes[i] = ' class="' + _class.join(' ') + '"';
                     that.header.formatters[i] = function (value, row, index) {
                         var colTree = [that.options.onTreeFormatter.apply(that, [row])];
                         colTree.push('<span class="' + that.options.treeTextcls + '">');
@@ -127,4 +127,4 @@
         return _initRow.apply(that, Array.prototype.slice.apply(arguments));
     };
 
-} (jQuery);
+} (jQuery);