ソースを参照

Merge pull request #50 from wenzhixin/master

Update my repo
Dennis Hernández 10 年 前
コミット
58de14ffff

+ 2 - 0
CHANGELOG.md

@@ -3,7 +3,9 @@
 - [enh] Accessing field name in formatter.
 - [enh] Improve function option to support string format for example formatter.
 - [enh] Added multiple sort extension.
+- [enh] Improve filter control extension.
 - [bug] Fix #912 Bug when switching to card view.
+- [bug] Fix #914: extra empty toolbar div bug.
 
 ### 1.8.0
 

+ 2 - 1
README.md

@@ -21,6 +21,7 @@ To get started, check out [Docs](http://bootstrap-table.wenzhixin.net.cn), [More
 * Philip Tepfer - $10
 * Marcus Eddy - $5
 * Keith Rockhold - $50
+* Ramon Sosa Diaz - $10
 
 ## LICENSE
 
@@ -65,7 +66,7 @@ npm install bootstrap-table
 
 ### CDN
 
-You can source bootstrap-table directly from a CDN like [CDNJS](http://www.cdnjs.com/libraries/bootstrap-table) or [bootcss](http://open.bootcss.com/bootstrap-table/).
+You can source bootstrap-table directly from a CDN like [CDNJS](http://www.cdnjs.com/libraries/bootstrap-table) or [bootcss](http://open.bootcss.com/bootstrap-table/) or [jsdelivr](http://www.jsdelivr.com/#!bootstrap.table).
 
 ## Reporting issues
 

+ 4 - 3
src/bootstrap-table.js

@@ -2251,8 +2251,9 @@
         'toggleView'
     ];
 
-    $.fn.bootstrapTable = function (option, _relatedTarget) {
-        var value;
+    $.fn.bootstrapTable = function (option) {
+        var value,
+            args = Array.prototype.slice.call(arguments, 1);
 
         this.each(function () {
             var $this = $(this),
@@ -2269,7 +2270,7 @@
                     return;
                 }
 
-                value = data[option](_relatedTarget);
+                value = data[option].apply(data, args);
 
                 if (option === 'destroy') {
                     $this.removeData('bootstrap.table');

+ 1 - 1
src/extensions/export/bootstrap-table-export.js

@@ -30,7 +30,7 @@
         _initToolbar = BootstrapTable.prototype.initToolbar;
 
     BootstrapTable.prototype.initToolbar = function () {
-        this.showToolbar = true;
+        this.showToolbar = this.options.showExport;
 
         _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
 

+ 68 - 25
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -69,7 +69,8 @@
     });
 
     $.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
-        filterControl: undefined
+        filterControl: undefined,
+        filterData: undefined
     });
 
     $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
@@ -119,6 +120,37 @@
             }
 
             that.$header.find(sprintf('.th-inner:contains("%s")', column.title)).next().append(html.join(''));
+            if (column.filterData !== undefined && column.filterData.toLowerCase() !== 'column') {
+                var filterDataType = column.filterData.substring(0, 3);
+                var filterDataSource = column.filterData.substring(4, column.filterData.length);
+                var selectControl = $('.' + column.field);
+                selectControl.append($("<option></option>")
+                    .attr("value", '')
+                    .text(''));
+                switch (filterDataType) {
+                    case 'url':
+                        $.ajax({
+                            url: filterDataSource,
+                            dataType: 'json',
+                            success: function (data) {
+                                $.each(data, function (key, value) {
+                                    selectControl.append($("<option></option>")
+                                        .attr("value", key)
+                                        .text(value));
+                                });
+                            }
+                        });
+                        break;
+                    case 'var':
+                        var variableValues = window[filterDataSource];
+                        for (var key in variableValues) {
+                            selectControl.append($("<option></option>")
+                                .attr("value", key)
+                                .text(variableValues[key]));
+                        };
+                        break;
+                }
+            }
         });
 
         if (addedFilterControl) {
@@ -158,31 +190,42 @@
                     that.header.formatters[j], [value, item, i], value);
 
                 if ((!column.checkbox) || (!column.radio)) {
-                    if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'select' && column.searchable) {
-                        var selectControl = $('.' + column.field),
-                            iOpt = 0,
-                            existsOpt = false,
-                            options;
-                        if (selectControl !== undefined) {
-                            options = selectControl.get(0).options;
-
-                            if (options.length === 0) {
-                                //Added the default option
-                                selectControl.append($("<option></option>").attr("value", '').text(''));
-                            }
-
-                            for (; iOpt < options.length; iOpt++) {
-                                if (options[iOpt].value === value) {
-                                    existsOpt = true;
-                                    break;
+                    if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'select'
+                            && column.searchable) {
+
+                        if (column.filterData === undefined || column.filterData.toLowerCase() === 'column') {
+                            var selectControl = $('.' + column.field),
+                                    iOpt = 0,
+                                    exitsOpt = false,
+                                    options;
+                            if (selectControl !== undefined) {
+                                options = selectControl.get(0).options;
+
+                                if (options.length === 0) {
+
+                                    //Added the default option
+                                    selectControl.append($("<option></option>")
+                                        .attr("value", '')
+                                        .text(''));
+
+                                    selectControl.append($("<option></option>")
+                                        .attr("value", value)
+                                        .text(value));
+                                } else {
+                                    for (; iOpt < options.length; iOpt++) {
+                                        if (options[iOpt].value === value) {
+                                            exitsOpt = true;
+                                            break;
+                                        }
+                                    }
+
+                                    if (!exitsOpt) {
+                                        selectControl.append($("<option></option>")
+                                            .attr("value", value)
+                                            .text(value));
+                                    }
                                 }
                             }
-
-                            if (!existsOpt) {
-                                selectControl.append($("<option></option>")
-                                    .attr("value", value)
-                                    .text(value));
-                            }
                         }
                     }
                 }
@@ -233,4 +276,4 @@
         this.updatePagination();
         this.trigger('column-search', $field, text);
     };
-}(jQuery);
+}(jQuery);

+ 1 - 0
src/extensions/multiple-sort/bootstrap-table-multiple-sort.js

@@ -127,6 +127,7 @@
                         $($alert).remove();
                     }
 
+                    that.options.sortName = "";
                     that.onMultipleSort();
                     $sortModal.modal('hide');
                 }