Browse Source

Merge branch 'develop' of https://github.com/manukieli/bootstrap-table into develop

manukieli 6 years ago
parent
commit
2866a182b3
4 changed files with 55 additions and 5 deletions
  1. 1 1
      site/docs/api/column-options.md
  2. 27 0
      site/docs/api/table-options.md
  3. 23 3
      src/bootstrap-table.js
  4. 4 1
      src/constants/index.js

+ 1 - 1
site/docs/api/column-options.md

@@ -332,7 +332,7 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
 
 - **Default:** `undefined`
 
-- **Example:** [Column Sorter](https://examples.bootstrap-table.com/#column-options/column-sorter.html)
+- **Example:** [Column Sorter](https://examples.bootstrap-table.com/#column-options/sorter.html)
 
 ## visible
 

+ 27 - 0
site/docs/api/table-options.md

@@ -69,6 +69,33 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
 
 - **Example:** [Thead Classes](https://examples.bootstrap-table.com/#options/thead-classes.html)
 
+## headerStyle
+
+- **Attribute:** `data-header-style`
+
+- **Type:** `Function`
+
+- **Detail:**
+
+  The header style formatter function, takes one parameter:
+
+  * `column`: the column object.
+
+  Support `classes` or `css`. Example usage:
+
+  {% highlight javascript %}
+  function headerStyle(column) {
+    return {
+      css: { 'font-weight': 'normal' },
+      classes: 'my-class'
+    }
+  }
+  {% endhighlight %}
+
+- **Default:** `{}`
+
+- **Example:** [Header Style](https://examples.bootstrap-table.com/#options/header-style.html)
+
 ## rowStyle
 
 - **Attribute:** `data-row-style`

+ 23 - 3
src/bootstrap-table.js

@@ -252,6 +252,20 @@ class BootstrapTable {
           return
         }
 
+        const headerStyle = Utils.calculateObjectValue(null, this.options.headerStyle, [column])
+        const csses = []
+        let classes = ''
+
+        if (headerStyle && headerStyle.css) {
+          for (const [key, value] of Object.entries(headerStyle.css)) {
+            csses.push(`${key}: ${value}`)
+          }
+        }
+        if (headerStyle && headerStyle.classes) {
+          classes = Utils.sprintf(' class="%s"', column['class'] ?
+            [column['class'], headerStyle.classes].join(' ') : headerStyle.classes)
+        }
+
         if (typeof column.fieldIndex !== 'undefined') {
           this.header.fields[column.fieldIndex] = column.field
           this.header.styles[column.fieldIndex] = align + style
@@ -278,8 +292,8 @@ class BootstrapTable {
         html.push(`<th${Utils.sprintf(' title="%s"', column.titleTooltip)}`,
           column.checkbox || column.radio
             ? Utils.sprintf(' class="bs-checkbox %s"', column['class'] || '')
-            : class_,
-          Utils.sprintf(' style="%s"', halign + style),
+            : classes || class_,
+          Utils.sprintf(' style="%s"', halign + style + csses.join('; ')),
           Utils.sprintf(' rowspan="%s"', column.rowspan),
           Utils.sprintf(' colspan="%s"', column.colspan),
           Utils.sprintf(' data-field="%s"', column.field),
@@ -1982,7 +1996,13 @@ class BootstrapTable {
 
   getData (params) {
     let data = this.options.data
-    if (this.searchText || this.options.sortName || !Utils.isEmptyObject(this.filterColumns) || !Utils.isEmptyObject(this.filterColumnsPartial)) {
+    if (
+      this.searchText ||
+      this.options.customSearch ||
+      this.options.sortName ||
+      !Utils.isEmptyObject(this.filterColumns) ||
+      !Utils.isEmptyObject(this.filterColumnsPartial)
+    ) {
       data = this.data
     }
 

+ 4 - 1
src/constants/index.js

@@ -112,6 +112,9 @@ const DEFAULTS = {
   height: undefined,
   classes: 'table table-bordered table-hover',
   theadClasses: '',
+  headerStyle (column) {
+    return {}
+  },
   rowStyle (row, index) {
     return {}
   },
@@ -185,7 +188,7 @@ const DEFAULTS = {
   customSearch: undefined,
   showHeader: true,
   showFooter: false,
-  footerStyle (row, index) {
+  footerStyle (column) {
     return {}
   },
   showColumns: false,