Browse Source

Added tr class support for thead (#5089)

* Added tr class support for thead

* Remove unused templates
文翼 5 years ago
parent
commit
770a6c1fb4
2 changed files with 19 additions and 27 deletions
  1. 0 17
      .github/ISSUE_TEMPLATE.md
  2. 19 10
      src/bootstrap-table.js

+ 0 - 17
.github/ISSUE_TEMPLATE.md

@@ -1,17 +0,0 @@
-<!-- https://github.com/wenzhixin/bootstrap-table/blob/develop/CONTRIBUTING.md#bug-reports -->
-
-
-Short and descriptive example bug report title
-
-A summary of the issue and the browser/OS environment in which it occurs. If suitable, include the steps required to reproduce the bug.
-
-This is the first step
-This is the second step
-Further steps, etc.
-
-Please provide an [Online Example](https://live.bootstrap-table.com) to show your problem, thanks!
-
-Any other information you want to share that is relevant to the issue being reported. This might include the lines of code that you have identified as causing the bug, and potential solutions (and your opinions on their merits).
-
-<!-- Love bootstrap-table? Please consider supporting our collective:
-👉  https://opencollective.com/bootstrap-table/donate -->

+ 19 - 10
src/bootstrap-table.js

@@ -139,23 +139,32 @@ class BootstrapTable {
     } else if (this.options.theadClasses) {
       this.$header.addClass(this.options.theadClasses)
     }
+
+    this._headerTrClasses = []
     this.$header.find('tr').each((i, el) => {
+      const $tr = $(el)
       const column = []
 
-      $(el).find('th').each((i, el) => {
+      $tr.find('th').each((i, el) => {
+        const $th = $(el)
+
         // #2014: getFieldIndex and elsewhere assume this is string, causes issues if not
-        if (typeof $(el).data('field') !== 'undefined') {
-          $(el).data('field', `${$(el).data('field')}`)
+        if (typeof $th.data('field') !== 'undefined') {
+          $th.data('field', `${$th.data('field')}`)
         }
         column.push($.extend({}, {
-          title: $(el).html(),
-          'class': $(el).attr('class'),
-          titleTooltip: $(el).attr('title'),
-          rowspan: $(el).attr('rowspan') ? +$(el).attr('rowspan') : undefined,
-          colspan: $(el).attr('colspan') ? +$(el).attr('colspan') : undefined
-        }, $(el).data()))
+          title: $th.html(),
+          'class': $th.attr('class'),
+          titleTooltip: $th.attr('title'),
+          rowspan: $th.attr('rowspan') ? +$th.attr('rowspan') : undefined,
+          colspan: $th.attr('colspan') ? +$th.attr('colspan') : undefined
+        }, $th.data()))
       })
       columns.push(column)
+
+      if ($tr.attr('class')) {
+        this._headerTrClasses.push($tr.attr('class'))
+      }
     })
 
     if (!Array.isArray(this.options.columns[0])) {
@@ -222,7 +231,7 @@ class BootstrapTable {
     Utils.updateFieldGroup(this.options.columns)
 
     this.options.columns.forEach((columns, i) => {
-      html.push('<tr>')
+      html.push(`<tr${Utils.sprintf(' class="%s"', this._headerTrClasses[i])}>`)
 
       let detailViewTemplate = ''