浏览代码

Merge pull request #83 from wenzhixin/master

Update my repo
Dennis Hernández 10 年之前
父节点
当前提交
becb11ecfd

+ 18 - 1
CHANGELOG.md

@@ -1,6 +1,6 @@
 ## ChangeLog
 
-### 1.8.2
+### 1.9.0
 
 - [enh] Update bootstrap-table-cookie.js.
 - [enh] Use options for detailView's open/close icons.
@@ -11,6 +11,23 @@
 - [bug] Fix #938, fix #940: Multiple Sort and Hide/Show column.
 - [bug] Fix #970: click and dblclick bug on no-rows table.
 - [bug] Fix #967: unselected column while column sorted display error.
+- [enh] Support title feature in cells.
+- [enh] Improved cookie, mobile extension.
+- [enh] Added groupby, angular extension.
+- [enh] Added option for setting locale.
+- [enh] Added `exportDataType` option for export extension.
+- [enh] Add fa-IR, ca-ES, es-ES, et-EE and af-ZA locales.
+- [enh] Supported complex header with rowspans and colspans.
+- [enh] Added `searchFomatter` column option.
+- [bug] Fixed ResetRow function and undefined column search bug.
+- [bug] Fixed #639: footer resizing problem.
+- [enh] Added resetSearch method to reset the search text.
+- [enh] Supported flat json.
+- [enh] Improved reorder-columns extension.
+- [enh] Added multiple-search, accent-neutralise extension.
+- [enh] Added fixed-columns extension.
+- [enh] Added `$.fn.bootstrapTable.utils` tools.
+- [enh] Added `expandRow` and `collapseRow` methods.
 
 ### 1.8.1
 

+ 1 - 1
docs/_i18n/en/documentation/events.md

@@ -146,7 +146,7 @@
     <tr>
         <td>onLoadError</td>
         <td>load-error.bs.table</td>
-        <td>status</td>
+        <td>status, res</td>
         <td>Fires when some errors occur to load remote data.</td>
     </tr>
     <tr>

+ 7 - 0
docs/_i18n/en/documentation/table-options.md

@@ -108,6 +108,13 @@ The table options are defined in `jQuery.fn.bootstrapTable.defaults`.
         <td>The data to be loaded.</td>
     </tr>
     <tr>
+        <td>dataField</td>
+        <td>data-data-field</td>
+        <td>String</td>
+        <td>'rows'</td>
+        <td>Key in incoming json containing rows data list.</td>
+    </tr>
+    <tr>
         <td>ajax</td>
         <td>data-ajax</td>
         <td>Function</td>

+ 2 - 2
docs/_includes/nav/main.html

@@ -28,8 +28,8 @@
                     <a href="http://issues.wenzhixin.net.cn/bootstrap-table/" target="_blank">Examples</a>
                 </li>
                 <li>
-                    <a href="http://bootstrap-group-select.wenzhixin.net.cn" target="_blank">
-                        Bootstrap Group Select
+                    <a href="https://github.com/wenzhixin/bootstrap-table-fixed-columns" target="_blank">
+                        Fixed Columns
                         <span class="badge">New</span>
                     </a>
                 </li>

+ 73 - 42
src/bootstrap-table.js

@@ -4,7 +4,7 @@
  * https://github.com/wenzhixin/bootstrap-table/
  */
 
-! function ($) {
+!function ($) {
     'use strict';
 
     // TOOLS DEFINITION
@@ -95,7 +95,7 @@
                 }
             }
         }
-    }
+    };
 
     var getScrollBarWidth = function () {
         if (cachedWidth === null) {
@@ -211,6 +211,15 @@
         return dataAttr;
     };
 
+    var getItemField = function (item, field) {
+        var props = field.split('.');
+        var value = item;
+        for (var p in props) {
+            value = value[props[p]];
+        }
+        return value;
+    }
+
     // BOOTSTRAP TABLE CLASS DEFINITION
     // ======================
 
@@ -234,6 +243,7 @@
         striped: false,
         columns: [[]],
         data: [],
+        dataField: 'rows',
         method: 'get',
         url: undefined,
         ajax: undefined,
@@ -514,26 +524,26 @@
             }
         }
     };
-    
+
     BootstrapTable.prototype.initContainer = function () {
         this.$container = $([
             '<div class="bootstrap-table">',
-                '<div class="fixed-table-toolbar"></div>',
-                    this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
-                    '<div class="fixed-table-pagination" style="clear: both;"></div>' :
-                    '',
-                '<div class="fixed-table-container">',
-                '<div class="fixed-table-header"><table></table></div>',
-                '<div class="fixed-table-body">',
-                    '<div class="fixed-table-loading">',
-                        this.options.formatLoadingMessage(),
-                    '</div>',
-                '</div>',
-                '<div class="fixed-table-footer"><table><tr></tr></table></div>',
-                this.options.paginationVAlign === 'bottom' || this.options.paginationVAlign === 'both' ?
+            '<div class="fixed-table-toolbar"></div>',
+            this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
+                '<div class="fixed-table-pagination" style="clear: both;"></div>' :
+                '',
+            '<div class="fixed-table-container">',
+            '<div class="fixed-table-header"><table></table></div>',
+            '<div class="fixed-table-body">',
+            '<div class="fixed-table-loading">',
+            this.options.formatLoadingMessage(),
+            '</div>',
+            '</div>',
+            '<div class="fixed-table-footer"><table><tr></tr></table></div>',
+            this.options.paginationVAlign === 'bottom' || this.options.paginationVAlign === 'both' ?
                 '<div class="fixed-table-pagination"></div>' :
                 '',
-                '</div>',
+            '</div>',
             '</div>'
         ].join(''));
 
@@ -704,8 +714,8 @@
 
                 html.push('<th' + sprintf(' title="%s"', column.titleTooltip),
                     column.checkbox || column.radio ?
-                    sprintf(' class="bs-checkbox %s"', column['class'] || '') :
-                    class_,
+                        sprintf(' class="bs-checkbox %s"', column['class'] || '') :
+                        class_,
                     sprintf(' style="%s"', halign + style),
                     sprintf(' rowspan="%s"', column.rowspan),
                     sprintf(' colspan="%s"', column.colspan),
@@ -752,7 +762,7 @@
         this.$header.children().children().off('keypress').on('keypress', function (event) {
             if (that.options.sortable && $(this).data().sortable) {
                 var code = event.keyCode || event.which;
-                if(code == 13) { //Enter keycode
+                if (code == 13) { //Enter keycode
                     that.onSort(event);
                 }
             }
@@ -825,8 +835,8 @@
                 if (that.header.sortNames[index]) {
                     name = that.header.sortNames[index];
                 }
-                var aa = a[name],
-                    bb = b[name],
+                var aa = getItemField(a, name),
+                    bb = getItemField(b, name),
                     value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
 
                 if (value !== undefined) {
@@ -1093,7 +1103,7 @@
                             }
                         } else {
                             if ((value + '').toLowerCase().indexOf(s) !== -1) {
-                               return true;
+                                return true;
                             }
                         }
                     }
@@ -1166,10 +1176,10 @@
         var pageNumber = [
                 sprintf('<span class="btn-group %s">',
                     this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
-                    'dropdown' : 'dropup'),
+                        'dropdown' : 'dropup'),
                 '<button type="button" class="btn btn-default ' +
-                    (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) +
-                    ' dropdown-toggle" data-toggle="dropdown">',
+                (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) +
+                ' dropdown-toggle" data-toggle="dropdown">',
                 '<span class="page-size">',
                 $allSelected ? this.options.formatAllRows() : this.options.pageSize,
                 '</span>',
@@ -1416,7 +1426,7 @@
 
             $.each(this.header.fields, function (j, field) {
                 var text = '',
-                    value = item[field],
+                    value = getItemField(item, field),
                     type = '',
                     cellStyle = {},
                     id_ = '',
@@ -1483,9 +1493,9 @@
                         sprintf(' type="%s"', type) +
                         sprintf(' value="%s"', item[that.options.idField]) +
                         sprintf(' checked="%s"', value === true ||
-                            (value && value.checked) ? 'checked' : undefined) +
+                        (value && value.checked) ? 'checked' : undefined) +
                         sprintf(' disabled="%s"', !column.checkboxEnabled ||
-                            (value && value.disabled) ? 'disabled' : undefined) +
+                        (value && value.disabled) ? 'disabled' : undefined) +
                         ' />',
                         that.options.cardView ? '</div>' : '</td>'
                     ].join('');
@@ -1543,7 +1553,7 @@
                 index = $td[0].cellIndex,
                 field = that.header.fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
                 colomn = that.columns[getFieldIndex(that.columns, field)],
-                value = item[field];
+                value = getItemField(item, field);
 
             if ($td.find('.detail-icon').length) {
                 return;
@@ -1706,7 +1716,7 @@
                 that.trigger('load-success', res);
             },
             error: function (res) {
-                that.trigger('load-error', res.status);
+                that.trigger('load-error', res.status, res);
             },
             complete: function () {
                 if (!silent) {
@@ -1804,19 +1814,19 @@
         fixedBody = this.$tableBody.get(0);
 
         scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth &&
-            fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ?
+        fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ?
             getScrollBarWidth() : 0;
 
         this.$el.css('margin-top', -this.$header.outerHeight());
 
         focused = $(':focus');
-        if(focused.length > 0) {
+        if (focused.length > 0) {
             var $th = focused.parents('th');
-            if($th.length > 0) {
+            if ($th.length > 0) {
                 var dataField = $th.attr('data-field');
-                if(dataField !== undefined) {
+                if (dataField !== undefined) {
                     var $headerTh = this.$header.find("[data-field='" + dataField + "']");
-                    if($headerTh.length > 0) {
+                    if ($headerTh.length > 0) {
                         $headerTh.find(":input").addClass("focus-temp");
                     }
                 }
@@ -1833,7 +1843,7 @@
 
 
         focusedTemp = $('.focus-temp:visible:eq(0)');
-        if(focusedTemp.length > 0) {
+        if (focusedTemp.length > 0) {
             focusedTemp.focus();
             this.$header.find('.focus-temp').removeClass('focus-temp');
         }
@@ -1933,8 +1943,8 @@
         scrollWidth = elWidth > this.$tableBody.width() ? getScrollBarWidth() : 0;
 
         this.$tableFooter.css({
-                'margin-right': scrollWidth
-            }).find('table').css('width', elWidth)
+            'margin-right': scrollWidth
+        }).find('table').css('width', elWidth)
             .attr('class', this.$el.attr('class'));
 
         $footerTd = this.$tableFooter.find('td');
@@ -2055,7 +2065,7 @@
         if (this.options.sidePagination === 'server') {
             this.options.totalRows = data.total;
             fixedScroll = data.fixedScroll;
-            data = data.rows;
+            data = data[this.options.dataField];
         } else if (!$.isArray(data)) { // support fixedScroll
             fixedScroll = data.fixedScroll;
             data = data.data;
@@ -2393,7 +2403,7 @@
     };
 
     BootstrapTable.prototype.getHiddenColumns = function () {
-        return $.grep(this.columns, function( column ) {
+        return $.grep(this.columns, function (column) {
             return !column.visible;
         });
     };
@@ -2468,6 +2478,20 @@
         this.onSearch({currentTarget: $search});
     };
 
+    BootstrapTable.prototype.expandRow = function (index) {
+        var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', index));
+        if (!$tr.next().is('tr.detail-view')) {
+            $tr.find('> td > .detail-icon').click();
+        }
+    };
+
+    BootstrapTable.prototype.collapseRow = function (index) {
+        var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', index));
+        if ($tr.next().is('tr.detail-view')) {
+            $tr.find('> td > .detail-icon').click();
+        }
+    };
+
     // BOOTSTRAP TABLE PLUGIN DEFINITION
     // =======================
 
@@ -2494,7 +2518,8 @@
         'togglePagination',
         'toggleView',
         'refreshOptions',
-        'resetSearch'
+        'resetSearch',
+        'expandRow', 'collapseRow'
     ];
 
     $.fn.bootstrapTable = function (option) {
@@ -2536,6 +2561,12 @@
     $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
     $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
     $.fn.bootstrapTable.methods = allowedMethods;
+    $.fn.bootstrapTable.utils = {
+        sprintf: sprintf,
+        getFieldIndex: getFieldIndex,
+        compareObjects: compareObjects,
+        calculateObjectValue: calculateObjectValue
+    };
 
     // BOOTSTRAP TABLE INIT
     // =======================

+ 3 - 44
src/extensions/accent-neutralise/bootstrap-table-accent-neutralise.js

@@ -1,5 +1,5 @@
 /**
- * @author: Dennis Hernández
+ * @author: Dennis Hernández
  * @webSite: http://djhvscf.github.io/Blog
  * @version: v1.0.0
  */
@@ -113,47 +113,6 @@
         });
     };
 
-    var getFieldIndex = function (columns, field) {
-        var index = -1;
-
-        $.each(columns, function (i, column) {
-            if (column.field === field) {
-                index = i;
-                return false;
-            }
-            return true;
-        });
-        return index;
-    };
-
-    var calculateObjectValue = function (self, name, args, defaultValue) {
-        var func = name;
-
-        if (typeof name === 'string') {
-            // support obj.func1.func2
-            var names = name.split('.');
-
-            if (names.length > 1) {
-                func = window;
-                $.each(names, function (i, f) {
-                    func = func[f];
-                });
-            } else {
-                func = window[name];
-            }
-        }
-        if (typeof func === 'object') {
-            return func;
-        }
-        if (typeof func === 'function') {
-            return func.apply(self, args);
-        }
-        if (!func && typeof name === 'string' && sprintf.apply(this, [name].concat(args))) {
-            return sprintf.apply(this, [name].concat(args));
-        }
-        return defaultValue;
-    };
-
     $.extend($.fn.bootstrapTable.defaults, {
         searchAccentNeutralise: false
     });
@@ -190,11 +149,11 @@
                 for (var key in item) {
                     key = $.isNumeric(key) ? parseInt(key, 10) : key;
                     var value = item[key],
-                        column = that.columns[getFieldIndex(that.columns, key)],
+                        column = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, key)],
                         j = $.inArray(key, that.header.fields);
 
                     if (column && column.searchFormatter) {
-                        value = calculateObjectValue(column,
+                        value = $.fn.bootstrapTable.utils.calculateObjectValue(column,
                             that.header.formatters[j], [value, item, i], value);
                     }
 

+ 9 - 62
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -8,61 +8,10 @@
 
     'use strict';
 
-    var sprintf = function (str) {
-        var args = arguments,
-            flag = true,
-            i = 1;
-
-        str = str.replace(/%s/g, function () {
-            var arg = args[i++];
-
-            if (typeof arg === 'undefined') {
-                flag = false;
-                return '';
-            }
-            return arg;
-        });
-        return flag ? str : '';
-    };
-
-    var getFieldIndex = function (columns, field) {
-        var index = -1;
-
-        $.each(columns, function (i, column) {
-            if (column.field === field) {
-                index = i;
-                return false;
-            }
-            return true;
-        });
-        return index;
-    };
-
-    var calculateObjectValue = function (self, name, args, defaultValue) {
-        if (typeof name === 'string') {
-            // support obj.func1.func2
-            var names = name.split('.');
-
-            if (names.length > 1) {
-                name = window;
-                $.each(names, function (i, f) {
-                    name = name[f];
-                });
-            } else {
-                name = window[name];
-            }
-        }
-        if (typeof name === 'object') {
-            return name;
-        }
-        if (typeof name === 'function') {
-            return name.apply(self, args);
-        }
-        return defaultValue;
-    };
+    var sprintf = $.fn.bootstrapTable.utils.sprintf;
 
     var addOptionToSelectControl = function (selectControl, value, text) {
-        //selectControl = $(selectControl.get(0));
+        selectControl = $(selectControl.get(selectControl.length - 1));
         if (existsOptionInSelectControl(selectControl, value)) {
             selectControl.append($("<option></option>")
                 .attr("value", value)
@@ -87,11 +36,9 @@
     };
 
     var existsOptionInSelectControl = function (selectControl, value) {
-        var options = selectControl.get(0).options,
-            iOpt = 0;
-
-        for (; iOpt < options.length; iOpt++) {
-            if (options[iOpt].value === value) {
+        var options = selectControl.get(selectControl.length - 1).options;
+        for (var i = 0; i < options.length; i++) {
+            if (options[i].value === value.toString()) {
                 //The value is nor valid to add
                 return false;
             }
@@ -386,16 +333,16 @@
 
             $.each(this.header.fields, function (j, field) {
                 var value = item[field],
-                    column = that.columns[getFieldIndex(that.columns, field)];
+                    column = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, field)];
 
-                value = calculateObjectValue(that.header, that.header.formatters[j], [value, item, i], value);
+                value = $.fn.bootstrapTable.utils.calculateObjectValue(that.header, that.header.formatters[j], [value, item, i], value);
 
                 if ((!column.checkbox) || (!column.radio)) {
                     if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'select' && column.searchable) {
                         if (column.filterData === undefined || column.filterData.toLowerCase() === 'column') {
                             var selectControl = $('.' + column.field);
                             if (selectControl !== undefined && selectControl.length > 0) {
-                                if (selectControl.get(0).options.length === 0) {
+                                if (selectControl.get(selectControl.length - 1).options.length === 0) {
                                     //Added the default option
                                     addOptionToSelectControl(selectControl, '', '');
                                 }
@@ -421,7 +368,7 @@
             for (var key in fp) {
                 var fval = fp[key].toLowerCase();
                 var value = item[key];
-                value = calculateObjectValue(that.header,
+                value = $.fn.bootstrapTable.utils.calculateObjectValue(that.header,
                     that.header.formatters[$.inArray(key, that.header.fields)],
                     [value, item, i], value);
 

+ 30 - 72
src/extensions/group-by/bootstrap-table-group-by.js

@@ -14,48 +14,6 @@
         obj = {},
         parentId = undefined;
 
-    var compareObjects = function (objectA, objectB, compareLength) {
-        // Create arrays of property names
-        var objectAProperties = Object.getOwnPropertyNames(objectA),
-            objectBProperties = Object.getOwnPropertyNames(objectB),
-            propName = '';
-
-        if (compareLength) {
-            // If number of properties is different, objects are not equivalent
-            if (objectAProperties.length !== objectBProperties.length) {
-                return false;
-            }
-        }
-
-        for (var i = 0; i < objectAProperties.length; i++) {
-            propName = objectAProperties[i];
-
-            // If the property is not in the object B properties, continue with the next property
-            if ($.inArray(propName, objectBProperties) > -1) {
-                // If values of same property are not equal, objects are not equivalent
-                if (objectA[propName] !== objectB[propName]) {
-                    return false;
-                }
-            }
-        }
-
-        // If we made it this far, objects are considered equivalent
-        return true;
-    };
-
-    var getFieldIndex = function (columns, field) {
-        var index = -1;
-
-        $.each(columns, function (i, column) {
-            if (column.field === field) {
-                index = i;
-                return false;
-            }
-            return true;
-        });
-        return index;
-    };
-
     var getParentRowId = function (that, id) {
         var parentRows = that.$body.find('tr').not('[' + 'data-tt-parent-id]');
 
@@ -72,15 +30,15 @@
         var sumRow = {};
         $.each(data, function (i, row) {
             if (!row.IsParent) {
-                for(var prop in row) {
-                        if (!isNaN(parseFloat(row[prop]))) {
-                            if (that.columns[getFieldIndex(that.columns, prop)].groupBySumGroup) {
-                                if (sumRow[prop] === undefined) {
-                                    sumRow[prop] = 0;
-                                }
-                                sumRow[prop] += +row[prop];
+                for (var prop in row) {
+                    if (!isNaN(parseFloat(row[prop]))) {
+                        if (that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, prop)].groupBySumGroup) {
+                            if (sumRow[prop] === undefined) {
+                                sumRow[prop] = 0;
                             }
+                            sumRow[prop] += +row[prop];
                         }
+                    }
                 }
             }
         });
@@ -105,19 +63,19 @@
 
     var setObjectKeys = function () {
         // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
-       Object.keys = function (o) {
-           if (o !== Object(o)) {
-               throw new TypeError('Object.keys called on a non-object');
-           }
-           var k = [],
-               p;
-           for (p in o) {
-               if (Object.prototype.hasOwnProperty.call(o, p)) {
-                   k.push(p);
-               }
-           }
-           return k;
-       }
+        Object.keys = function (o) {
+            if (o !== Object(o)) {
+                throw new TypeError('Object.keys called on a non-object');
+            }
+            var k = [],
+                p;
+            for (p in o) {
+                if (Object.prototype.hasOwnProperty.call(o, p)) {
+                    k.push(p);
+                }
+            }
+            return k;
+        }
     };
 
     var getDataArrayFromItem = function (that, item) {
@@ -140,16 +98,16 @@
         return newRow;
     };
 
-    var groupBy = function (array , f) {
-       var groups = {};
-       $.each(array, function(i, o) {
-           var group = JSON.stringify(f(o));
-           groups[group] = groups[group] || [];
-           groups[group].push(o);
-       });
-       return Object.keys(groups).map(function (group) {
+    var groupBy = function (array, f) {
+        var groups = {};
+        $.each(array, function (i, o) {
+            var group = JSON.stringify(f(o));
+            groups[group] = groups[group] || [];
+            groups[group].push(o);
+        });
+        return Object.keys(groups).map(function (group) {
             return groups[group];
-       });
+        });
     };
 
     var makeGrouped = function (that, data) {
@@ -277,7 +235,7 @@
     };
 
     BootstrapTable.prototype.refreshGroupByField = function (groupByFields) {
-        if (!compareObjects(this.options.groupByField, groupByFields)) {
+        if (!$.fn.bootstrapTable.utils.compareObjects(this.options.groupByField, groupByFields)) {
             this.options.groupByField = groupByFields;
             this.load(this.options.originalData);
         }

+ 1 - 14
src/extensions/mobile/bootstrap-table-mobile.js

@@ -8,25 +8,12 @@
 
     'use strict';
 
-    var getFieldIndex = function (columns, field) {
-        var index = -1;
-
-        $.each(columns, function (i, column) {
-            if (column.field === field) {
-                index = i;
-                return false;
-            }
-            return true;
-        });
-        return index;
-    };
-
     var showHideColumns = function (that, checked) {
         if (that.options.columnsHidden.length > 0 ) {
             $.each(that.columns, function (i, column) {
                 if (that.options.columnsHidden.indexOf(column.field) !== -1) {
                     if (column.visible !== checked) {
-                        that.toggleColumn(getFieldIndex(that.columns, column.field), checked, true);
+                        that.toggleColumn($.fn.bootstrapTable.utils.getFieldIndex(that.columns, column.field), checked, true);
                     }
                 }
             });

+ 2 - 60
src/extensions/multiple-search/bootstrap-table-multiple-search.js

@@ -8,64 +8,6 @@
 
     'use strict';
 
-    var sprintf = function (str) {
-        var args = arguments,
-            flag = true,
-            i = 1;
-
-        str = str.replace(/%s/g, function () {
-            var arg = args[i++];
-
-            if (typeof arg === 'undefined') {
-                flag = false;
-                return '';
-            }
-            return arg;
-        });
-        return flag ? str : '';
-    };
-
-    var getFieldIndex = function (columns, field) {
-        var index = -1;
-
-        $.each(columns, function (i, column) {
-            if (column.field === field) {
-                index = i;
-                return false;
-            }
-            return true;
-        });
-        return index;
-    };
-
-    var calculateObjectValue = function (self, name, args, defaultValue) {
-        var func = name;
-
-        if (typeof name === 'string') {
-            // support obj.func1.func2
-            var names = name.split('.');
-
-            if (names.length > 1) {
-                func = window;
-                $.each(names, function (i, f) {
-                    func = func[f];
-                });
-            } else {
-                func = window[name];
-            }
-        }
-        if (typeof func === 'object') {
-            return func;
-        }
-        if (typeof func === 'function') {
-            return func.apply(self, args);
-        }
-        if (!func && typeof name === 'string' && sprintf.apply(this, [name].concat(args))) {
-            return sprintf.apply(this, [name].concat(args));
-        }
-        return defaultValue;
-    };
-
     $.extend($.fn.bootstrapTable.defaults, {
         multipleSearch: false
     });
@@ -89,12 +31,12 @@
                         for (var key in item) {
                             key = $.isNumeric(key) ? parseInt(key, 10) : key;
                             var value = item[key],
-                                column = that.columns[getFieldIndex(that.columns, key)],
+                                column = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, key)],
                                 j = $.inArray(key, that.header.fields);
 
                             // Fix #142: search use formated data
                             if (column && column.searchFormatter) {
-                                value = calculateObjectValue(column,
+                                value = $.fn.bootstrapTable.utils.calculateObjectValue(column,
                                     that.header.formatters[j], [value, item, i], value);
                             }
 

+ 1 - 14
src/extensions/reorder-columns/bootstrap-table-reorder-columns.js

@@ -8,19 +8,6 @@
 
     'use strict';
 
-    var getFieldIndex = function (columns, field) {
-        var index = -1;
-
-        $.each(columns, function (i, column) {
-            if (column.field === field) {
-                index = i;
-                return false;
-            }
-            return true;
-        });
-        return index;
-    };
-
     $.extend($.fn.bootstrapTable.defaults, {
         reorderableColumns: false,
         maxMovingRows: 10,
@@ -116,7 +103,7 @@
                 }
 
                 for (var i = 0; i < ths.length; i++ ) {
-                    columnIndex = getFieldIndex(that.columns, ths[i]);
+                    columnIndex = $.fn.bootstrapTable.utils.getFieldIndex(that.columns, ths[i]);
                     if (columnIndex !== -1) {
                         columns.push(that.columns[columnIndex]);
                         that.columns.splice(columnIndex, 1);

+ 2 - 40
src/extensions/toolbar/bootstrap-table-toolbar.js

@@ -10,45 +10,7 @@
 
     var firstLoad = false;
 
-    var sprintf = function(str) {
-        var args = arguments,
-            flag = true,
-            i = 1;
-
-        str = str.replace(/%s/g, function() {
-            var arg = args[i++];
-
-            if (typeof arg === 'undefined') {
-                flag = false;
-                return '';
-            }
-            return arg;
-        });
-        return flag ? str : '';
-    };
-
-    var calculateObjectValue = function (self, name, args, defaultValue) {
-        if (typeof name === 'string') {
-            // support obj.func1.func2
-            var names = name.split('.');
-
-            if (names.length > 1) {
-                name = window;
-                $.each(names, function (i, f) {
-                    name = name[f];
-                });
-            } else {
-                name = window[name];
-            }
-        }
-        if (typeof name === 'object') {
-            return name;
-        }
-        if (typeof name === 'function') {
-            return name.apply(self, args);
-        }
-        return defaultValue;
-    };
+    var sprintf = $.fn.bootstrapTable.utils.sprintf;
 
     var showAvdSearch = function(pColumns, searchTitle, searchText, that) {
         if (!$("#avdSearchModal" + "_" + that.options.idTable).hasClass("modal")) {
@@ -214,7 +176,7 @@
             for (var key in fp) {
                 var fval = fp[key].toLowerCase();
                 var value = item[key];
-                value = calculateObjectValue(that.header,
+                value = $.fn.bootstrapTable.utils.calculateObjectValue(that.header,
                     that.header.formatters[$.inArray(key, that.header.fields)],
                     [value, item, i], value);
 

+ 40 - 0
src/locale/bootstrap-table-af-ZA.js

@@ -0,0 +1,40 @@
+/**
+ * Bootstrap Table Afrikaans translation
+ * Author: Phillip Kruger <phillip.kruger@gmail.com>
+ */
+(function ($) {
+    'use strict';
+
+    $.fn.bootstrapTable.locales['af-ZA'] = {
+        formatLoadingMessage: function () {
+            return 'Besig om te laai, wag asseblief ...';
+        },
+        formatRecordsPerPage: function (pageNumber) {
+            return pageNumber + ' rekords per bladsy';
+        },
+        formatShowingRows: function (pageFrom, pageTo, totalRows) {
+            return 'Resultate ' + pageFrom + ' tot ' + pageTo + ' van ' + totalRows + ' rye';
+        },
+        formatSearch: function () {
+            return 'Soek';
+        },
+        formatNoMatches: function () {
+            return 'Geen rekords gevind nie';
+        },
+        formatPaginationSwitch: function () {
+            return 'Wys/verberg bladsy nummering';
+        },
+        formatRefresh: function () {
+            return 'Herlaai';
+        },
+        formatToggle: function () {
+            return 'Wissel';
+        },
+        formatColumns: function () {
+            return 'Kolomme';
+        }
+    };
+
+    $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['af-ZA']);
+
+})(jQuery);

+ 43 - 0
src/locale/bootstrap-table-et-EE.js

@@ -0,0 +1,43 @@
+/**
+ * Bootstrap Table Estonian translation
+ * Author: kristjan@logist.it>
+ */
+(function ($) {
+    'use strict';
+
+    $.fn.bootstrapTable.locales['et-EE'] = {
+        formatLoadingMessage: function () {
+            return 'Päring käib, palun oota...';
+        },
+        formatRecordsPerPage: function (pageNumber) {
+            return pageNumber + ' rida lehe kohta';
+        },
+        formatShowingRows: function (pageFrom, pageTo, totalRows) {
+            return 'Näitan tulemusi ' + pageFrom + ' kuni ' + pageTo + ' - kokku ' + totalRows + ' tulemust';
+        },
+        formatSearch: function () {
+            return 'Otsi';
+        },
+        formatNoMatches: function () {
+            return 'Päringu tingimustele ei vastanud ühtegi tulemust';
+        },
+        formatPaginationSwitch: function () {
+            return 'Näita/Peida lehtedeks jagamine';
+        },
+        formatRefresh: function () {
+            return 'Värskenda';
+        },
+        formatToggle: function () {
+            return 'Lülita';
+        },
+        formatColumns: function () {
+            return 'Veerud';
+        },
+        formatAllRows: function () {
+            return 'Kõik';
+        }
+    };
+
+    $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['et-EE']);
+
+})(jQuery);