浏览代码

Merge pull request #2 from wenzhixin/develop

Updating my repo
Dennis Hernández 7 年之前
父节点
当前提交
02ae33b772

+ 3 - 0
dist/locale/bootstrap-table-pt-BR.js

@@ -28,6 +28,9 @@
         formatColumns: function () { 
             return 'Colunas';
         },
+        formatAllRows: function () {
+            return 'Todos';
+        },
         formatPaginationSwitch: function () { 
             return 'Ocultar/Exibir paginação';
         },

+ 1 - 1
docs/_i18n/zh-cn/documentation/events.md

@@ -206,7 +206,7 @@
     <tr>
         <td>onPostBody</td>
         <td>post-body.bs.table</td>
-        <td>none</td>
+        <td>data</td>
         <td>
         在表格 body 渲染完成后触发。
         </td>

+ 21 - 10
src/bootstrap-table.js

@@ -10,7 +10,13 @@
 
   let bootstrapVersion = 3
   try {
-    bootstrapVersion = parseInt($.fn.dropdown.Constructor.VERSION, 10)
+    var rawVersion = $.fn.dropdown.Constructor.VERSION
+
+    // Only try to parse VERSION if is is defined.
+    // It is undefined in older versions of Bootstrap (tested with 3.1.1).
+    if (rawVersion !== undefined) {
+      bootstrapVersion = parseInt(rawVersion, 10)
+    }
   } catch (e) {}
 
   const bootstrap = {
@@ -166,7 +172,7 @@
 
         if (names.length > 1) {
           func = window
-          for (const f of name) {
+          for (const f of names) {
             func = func[f]
           }
         } else {
@@ -825,7 +831,8 @@
             Utils.sprintf(' rowspan="%s"', column.rowspan),
             Utils.sprintf(' colspan="%s"', column.colspan),
             Utils.sprintf(' data-field="%s"', column.field),
-            j === 0 && column.fieldIndex ? ' data-not-first-th' : '',
+            // If `column` is not the first element of `this.options.columns[0]`, then className 'data-not-first-th' should be added.
+            j === 0 && i > 0 ? ' data-not-first-th' : '',
             '>')
 
           html.push(Utils.sprintf('<div class="th-inner %s">', this.options.sortable && column.sortable
@@ -1254,7 +1261,11 @@
     initSearch () {
       if (this.options.sidePagination !== 'server') {
         if (this.options.customSearch !== $.noop) {
-          window[this.options.customSearch].apply(this, [this.searchText])
+          if (typeof this.options.customSearch === 'string') {
+            window[this.options.customSearch].apply(this, [this.searchText])
+          } else {
+            this.options.customSearch.apply(this, [this.searchText])
+          }
           return
         }
 
@@ -1295,16 +1306,16 @@
                   value = value[props[i]]
                 }
               }
-
-              // Fix #142: respect searchForamtter boolean
-              if (column && column.searchFormatter) {
-                value = Utils.calculateObjectValue(column,
-                  this.header.formatters[j], [value, item, i], value)
-              }
             } else {
               value = item[key]
             }
 
+            // Fix #142: respect searchForamtter boolean
+            if (column && column.searchFormatter) {
+              value = Utils.calculateObjectValue(column,
+                this.header.formatters[j], [value, item, i], value)
+            }
+            
             if (typeof value === 'string' || typeof value === 'number') {
               if (this.options.strictSearch) {
                 if ((`${value}`).toLowerCase() === s) {

+ 1 - 1
src/extensions/accent-neutralise/bootstrap-table-accent-neutralise.js

@@ -158,7 +158,7 @@
                     }
 
                     var index = $.inArray(key, that.header.fields);
-                    if (index !== -1 && that.header.searchables[index] && (typeof value === 'string' || typeof value === 'number')) {
+                    if (index !== -1 && that.header.searchables[index] && typeof value === 'string') {
                         if (that.options.searchAccentNeutralise) {
                             value = removeDiacritics(value);
                             s = removeDiacritics(s);

+ 3 - 1
src/extensions/editable/README.md

@@ -20,8 +20,10 @@ Use Plugin: [x-editable](https://github.com/vitalets/x-editable)
 
 ### editable
 
-* type: Object
+* type: Object or Function
 * description: Configuration of x-editable. Full list of options: http://vitalets.github.io/x-editable/docs.html#editable
+* If it is type of Function, it is called with params: index, row, element for
+  each row of the table. It should return Object of the x-editable configuration.
 * default: `undefined`
 
 All options can be defined via `data-editable-*` HTML attributes. Table wide options are used for every column but can be overridden:

+ 14 - 0
src/extensions/editable/bootstrap-table-editable.js

@@ -111,6 +111,20 @@
                 return;
             }
 
+            var data = that.getData();
+
+            that.$body.find('a[data-name="' + column.field + '"]').each(function(i, element){
+                var $element = $(element);
+                var $tr = $element.closest('tr');
+                var index = $tr.data('index');
+                var row = data[index];
+
+                var editableOpts = $.fn.bootstrapTable.utils.calculateObjectValue(column, column.editable, [index, row, $element], {});
+
+                $element.editable(editableOpts);
+            });
+
+
             that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
                 .off('save').on('save', function(e, params) {
                     var data = that.getData(),

+ 73 - 62
src/extensions/export/bootstrap-table-export.js

@@ -60,6 +60,8 @@
   })
   $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales)
 
+  $.fn.bootstrapTable.methods.push('exportTable')
+
   $.BootstrapTable = class extends $.BootstrapTable {
     initToolbar () {
       const o = this.options
@@ -106,87 +108,96 @@
 
       $menu.find('>li, >a').click(e => {
         const type = $(e.currentTarget).data('type')
-        const doExport = () => {
-          const data = this.getData()
-          if (o.exportFooter) {
-            const $footerRow = this.$tableFooter.find('tr').first()
-            const footerData = {}
-            const footerHtml = []
+        const exportOptions = {
+            type: type,
+            escape: false
+        }
 
-            $.each($footerRow.children(), function (index, footerCell) {
-              var footerCellHtml = $(footerCell).children('.th-inner').first().html()
-              footerData[this.columns[index].field] = footerCellHtml === '&nbsp;' ? null : footerCellHtml
+        this.exportTable(exportOptions)
+      })
+    }
 
-              // grab footer cell text into cell index-based array
-              footerHtml.push(footerCellHtml)
-            })
+    exportTable(options) {
+      const o = this.options
 
-            this.append(footerData)
+      const doExport = () => {
+        const that = this
+        const data = this.getData()
+        if (o.exportFooter) {
+          const $footerRow = this.$tableFooter.find('tr').first()
+          const footerData = {}
+          const footerHtml = []
 
-            var $lastTableRow = this.$body.children().last()
+          $.each($footerRow.children(), function (index, footerCell) {
+            var footerCellHtml = $(footerCell).children('.th-inner').first().html()
+            footerData[that.columns[index].field] = footerCellHtml === '&nbsp;' ? null : footerCellHtml
 
-            $.each($lastTableRow.children(), function (index, lastTableRowCell) {
-              $(lastTableRowCell).html(footerHtml[index])
-            })
-          }
+            // grab footer cell text into cell index-based array
+            footerHtml.push(footerCellHtml)
+          })
 
-          this.$el.tableExport($.extend({}, o.exportOptions, {
-            type: type,
-            escape: false
-          }))
+          this.append(footerData)
 
-          if (o.exportFooter) {
-            this.load(data)
-          }
-        }
+          var $lastTableRow = this.$body.children().last()
 
-        const stateField = this.header.stateField
-
-        if (o.exportDataType === 'all' && o.pagination) {
-          const eventName = o.sidePagination === 'server'
-            ? 'post-body.bs.table' : 'page-change.bs.table'
-          this.$el.one(eventName, () => {
-            if (stateField) {
-              this.hideColumn(stateField)
-            }
-            doExport()
-            this.togglePagination()
+          $.each($lastTableRow.children(), function (index, lastTableRowCell) {
+            $(lastTableRowCell).html(footerHtml[index])
           })
-          this.togglePagination()
-        } else if (o.exportDataType === 'selected') {
-          let data = this.getData()
-          let selectedData = this.getSelections()
-          if (!selectedData.length) {
-            return
-          }
+        }
 
-          if (o.sidePagination === 'server') {
-            data = {
-              total: o.totalRows,
-              [this.options.dataField]: data
-            }
-            selectedData = {
-              total: selectedData.length,
-              [this.options.dataField]: selectedData
-            }
-          }
+        this.$el.tableExport($.extend({}, o.exportOptions, options))
 
-          this.load(selectedData)
-          if (stateField) {
-            this.hideColumn(stateField)
-          }
-          doExport()
+        if (o.exportFooter) {
           this.load(data)
-        } else {
+        }
+      }
+
+      const stateField = this.header.stateField
+
+      if (o.exportDataType === 'all' && o.pagination) {
+        const eventName = o.sidePagination === 'server'
+          ? 'post-body.bs.table' : 'page-change.bs.table'
+        this.$el.one(eventName, () => {
           if (stateField) {
             this.hideColumn(stateField)
           }
           doExport()
+          this.togglePagination()
+        })
+        this.togglePagination()
+      } else if (o.exportDataType === 'selected') {
+        let data = this.getData()
+        let selectedData = this.getSelections()
+        if (!selectedData.length) {
+          return
+        }
+
+        if (o.sidePagination === 'server') {
+          data = {
+            total: o.totalRows,
+            [this.options.dataField]: data
+          }
+          selectedData = {
+            total: selectedData.length,
+            [this.options.dataField]: selectedData
+          }
         }
+
+        this.load(selectedData)
         if (stateField) {
-          this.showColumn(stateField)
+          this.hideColumn(stateField)
         }
-      })
+        doExport()
+        this.load(data)
+      } else {
+        if (stateField) {
+          this.hideColumn(stateField)
+        }
+        doExport()
+      }
+      if (stateField) {
+        this.showColumn(stateField)
+      }
     }
   }
 })(jQuery)

+ 1 - 1
src/locale/bootstrap-table-de-DE.js

@@ -13,7 +13,7 @@
       return pageNumber + ' Zeilen pro Seite.';
     },
     formatShowingRows: function (pageFrom, pageTo, totalRows) {
-      return 'Zeige Zeile ' + pageFrom + ' bis ' + pageTo + ' von ' + totalRows + ' Zeilen' + ((totalRows > 1) ? "n" : "")+".";
+      return 'Zeige Zeile ' + pageFrom + ' bis ' + pageTo + ' von ' + totalRows + ' Zeile' + ((totalRows > 1) ? "n" : "")+".";
     },
     formatDetailPagination: function (totalRows) {
       return 'Zeige ' + totalRows + ' Zeile' + ((totalRows > 1) ? "n" : "")+".";

+ 49 - 0
src/locale/bootstrap-table-fi-FI.js

@@ -0,0 +1,49 @@
+/**
+ * Bootstrap Table Finnish translations
+ * Author: Minna Lehtomäki <minna.j.lehtomaki@gmail.com>
+ */
+(function ($) {
+    'use strict';
+
+    $.fn.bootstrapTable.locales['fi-FI'] = {
+        formatLoadingMessage: function () {
+            return 'Ladataan, ole hyvä ja odota...';
+        },
+        formatRecordsPerPage: function (pageNumber) {
+            return pageNumber + ' riviä sivulla';
+        },
+        formatShowingRows: function (pageFrom, pageTo, totalRows) {
+            return 'Näytetään rivit ' + pageFrom + ' - ' + pageTo + ' / ' + totalRows;
+        },
+        formatSearch: function () {
+            return 'Hae';
+        },
+        formatNoMatches: function () {
+            return 'Hakuehtoja vastaavia tuloksia ei löytynyt';
+        },
+        formatPaginationSwitch: function () {
+            return 'Näytä/Piilota sivutus';
+        },
+        formatRefresh: function () {
+            return 'Päivitä';
+        },
+        formatToggle: function () {
+            return 'Valitse';
+        },
+        formatColumns: function () {
+            return 'Sarakkeet';
+        },
+        formatAllRows: function () {
+            return 'Kaikki';
+        },
+        formatExport: function () {
+            return 'Vie tiedot';
+        },
+        formatClearFilters: function () {
+            return 'Poista suodattimet';
+        }
+    };
+
+    $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['fi-FI']);
+
+})(jQuery);