Browse Source

Merge pull request #16 from wenzhixin/master

Update my repo
Dennis Hernández 10 years ago
parent
commit
3ca10d0d2c

+ 15 - 4
docs/_i18n/en/documentation/events.md

@@ -77,14 +77,20 @@
     <tr>
         <td>onCheckAll</td>
         <td>check-all.bs.table</td>
-        <td>none</td>
-        <td>Fires when user check all rows.</td>
+        <td>rows</td>
+        <td>
+        Fires when user check all rows, the parameters contains: <br>
+        rows: array of records corresponding to newly checked rows.
+        </td>
     </tr>
     <tr>
         <td>onUncheckAll</td>
         <td>uncheck-all.bs.table</td>
-        <td>none</td>
-        <td>Fires when user uncheck all rows.</td>
+        <td>rows</td>
+        <td>
+        Fires when user uncheck all rows, the parameters contains: <br>
+        rows: array of records corresponding to previously checked rows.
+        </td>
     </tr>
     <tr>
         <td>onLoadSuccess</td>
@@ -130,5 +136,10 @@
         <td>none</td>
         <td>Fires after the table body is rendered and available in the DOM</td>
     </tr>
+    <tr>
+       <td>onPostHeader</td>
+       <td>post-header.bs.table</td>
+       <td>none</td>
+       <td>Fires after the table header is rendered and availble in the DOM</td>
     </tbody>
 </table>

+ 22 - 0
docs/_i18n/en/documentation/methods.md

@@ -122,6 +122,28 @@ The calling method syntax: `$('#table').bootstrapTable('method', parameter);`.
         <td>Uncheck a row, the row index start with 0.</td>
     </tr>
     <tr>
+        <td>checkBy</td>
+        <td>params</td>
+        <td>
+        Check a row by array of values, the params contains:<br>
+        field: name of the field used to find records<br>
+        values: array of values for rows to check<br>
+        Example: <br>
+        $("#table").bootstrapTable("checkBy", {field:"field_name", values:["value1","value2","value3"]})
+        </td>
+    </tr>
+    <tr>
+        <td>uncheckBy</td>
+        <td>params</td>
+        <td>
+        Uncheck a row by array of values, the params contains:<br>
+        field: name of the field used to find records<br>
+        values: array of values for rows to uncheck<br>
+        Example: <br>
+        $("#table").bootstrapTable("uncheckBy", {field:"field_name", values:["value1","value2","value3"]})
+        </td>
+    </tr>
+    <tr>
         <td>resetView</td>
         <td>params</td>
         <td>Reset the bootstrap table view, for example reset the table height.</td>

+ 11 - 3
docs/_plugins/multiple-languages.rb

@@ -16,6 +16,7 @@ module Jekyll
       config['baseurl_root'] = self.config['baseurl']
       baseurl_org = self.config['baseurl']
       languages = self.config['languages']
+      exclude_org = self.exclude
       dest_org = self.dest
 
       #Loop
@@ -26,14 +27,21 @@ module Jekyll
       languages.drop(1).each do |lang|
 
         # Build site for language lang
-        self.dest = self.dest + "/" + lang
+        @dest = @dest + "/" + lang
         self.config['baseurl'] = self.config['baseurl'] + "/" + lang
         self.config['lang'] = lang
+        
+        # exclude folders or files from beeing copied to all the language folders
+        exclude_from_localizations = self.config['exclude_from_localizations'] || []
+        @exclude = @exclude + exclude_from_localizations
+
         puts "Building site for language: \"#{self.config['lang']}\" to: #{self.dest}"
         process_org
 
         #Reset variables for next language
-        self.dest = dest_org
+        @dest = dest_org
+        @exclude = exclude_org
+
         self.config['baseurl'] = baseurl_org
       end
       Jekyll.setlangs({})
@@ -142,4 +150,4 @@ end
 Liquid::Template.register_tag('t', Jekyll::LocalizeTag)
 Liquid::Template.register_tag('translate', Jekyll::LocalizeTag)
 Liquid::Template.register_tag('tf', Jekyll::Tags::LocalizeInclude)
-Liquid::Template.register_tag('translate_file', Jekyll::Tags::LocalizeInclude)
+Liquid::Template.register_tag('translate_file', Jekyll::Tags::LocalizeInclude)

+ 77 - 12
src/bootstrap-table.js

@@ -195,7 +195,8 @@
         onPageChange: function (number, size) {return false;},
         onSearch: function (text) {return false;},
         onPreBody: function (data) {return false;},
-        onPostBody: function () {return false;}
+        onPostBody: function () {return false;},
+        onPostHeader: function() {return false;}
     };
 
     BootstrapTable.LOCALES = [];
@@ -270,7 +271,8 @@
         'page-change.bs.table': 'onPageChange',
         'search.bs.table': 'onSearch',
         'pre-body.bs.table': 'onPreBody',
-        'post-body.bs.table': 'onPostBody'
+        'post-body.bs.table': 'onPostBody',
+        'post-header.bs.table' : 'onPostHeader'
     };
 
     BootstrapTable.prototype.init = function () {
@@ -355,6 +357,7 @@
                 // save td's id and class
                 row['_' + field + '_id'] = $(this).attr('id');
                 row['_' + field + '_class'] = $(this).attr('class');
+                row['_' + field + '_data'] = $(this).data();
             });
             data.push(row);
         });
@@ -502,12 +505,8 @@
                     return order * value;
                 }
 
-                // Convert numerical values form string to float.
-                if ($.isNumeric(aa)) {
-                    aa = parseFloat(aa);
-                }
-                if ($.isNumeric(bb)) {
-                    bb = parseFloat(bb);
+                if (value !== undefined) {
+                    return order * value;
                 }
 
                 // Fix #161: undefined or null string sort bug.
@@ -518,7 +517,11 @@
                     bb = '';
                 }
                 
+                // IF both values are numeric, do a numeric comparison
                 if ($.isNumeric(aa) && $.isNumeric(bb)) {
+                    // Convert numerical values form string to float.
+                    aa = parseFloat(aa);
+                    bb = parseFloat(bb);
                     if (aa < bb) {
                         return order * -1;
                     }
@@ -528,6 +531,13 @@
                 if (aa === bb) {
                     return 0;
                 }
+
+                // If value is not a string, convert to string
+                if (typeof aa !== 'string')
+                {
+                    aa = aa.toString();
+                }
+
                 if (aa.localeCompare(bb) === -1) {
                     return order * -1;
                 }
@@ -1020,6 +1030,7 @@
                     cellStyle = {},
                     id_ = '',
                     class_ = that.header.classes[j],
+                    data_ = '',
                     column = that.options.columns[getFieldIndex(that.options.columns, field)];
 
                 style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
@@ -1034,7 +1045,6 @@
                 if (item['_' + field + '_class']) {
                     class_ = sprintf(' class="%s"', item['_' + field + '_class']);
                 }
-
                 cellStyle = calculateObjectValue(that.header,
                     that.header.cellStyles[j], [value, item, i], cellStyle);
                 if (cellStyle.classes) {
@@ -1048,6 +1058,16 @@
                     style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
                 }
 
+                if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
+                    $.each(item['_' + field + '_data'], function (k, v) {
+                        // ignore data-index
+                        if (k === 'index') {
+                            return;
+                        }
+                        data_ += sprintf(' data-%s="%s"', k, v);
+                    });
+                }
+
                 if (column.checkbox || column.radio) {
                     type = column.checkbox ? 'checkbox' : type;
                     type = column.radio ? 'radio' : type;
@@ -1075,7 +1095,7 @@
                                 getPropertyFromOther(that.options.columns, 'field', 'title', field)) : '',
                             sprintf('<span class="value">%s</span>', value),
                             '</div>'].join('') :
-                        [sprintf('<td%s %s %s>', id_, class_, style),
+                        [sprintf('<td%s %s %s %s>', id_, class_, style, data_),
                             value,
                             '</td>'].join('');
 
@@ -1329,6 +1349,8 @@
             $fixedBody.off('scroll').on('scroll', function () {
                 $fixedHeader.scrollLeft($(this).scrollLeft());
             });
+            
+            that.trigger('post-header');
         });
     };
 
@@ -1386,6 +1408,8 @@
 
         if (this.options.showHeader && this.options.height) {
             this.resetHeader();
+        } else {
+            this.trigger('post-header');
         }
 
         if (this.options.height && this.options.showHeader) {
@@ -1398,16 +1422,22 @@
     };
 
     BootstrapTable.prototype.load = function (data) {
+        var fixedScroll = false;
+
         // #431: support pagination
         if (this.options.sidePagination === 'server') {
             this.options.totalRows = data.total;
+            fixedScroll = data.fixedScroll;
             data = data.rows;
+        } else if (!$.isArray(data)) { // support fixedScroll
+            fixedScroll = data.fixedScroll;
+            data = data.data;
         }
 
         this.initData(data);
         this.initSearch();
         this.initPagination();
-        this.initBody();
+        this.initBody(fixedScroll);
     };
 
     BootstrapTable.prototype.append = function (data) {
@@ -1511,10 +1541,17 @@
     };
 
     BootstrapTable.prototype.checkAll_ = function (checked) {
+        var rows;
+        if(!checked) {
+            rows = this.getSelections();
+        }
         this.$selectItem.filter(':enabled').prop('checked', checked);
         this.updateRows(checked);
         this.updateSelected();
-        this.trigger(checked ? 'check-all' : 'uncheck-all');
+        if(checked) {
+            rows = this.getSelections();
+        }
+        this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
     };
 
     BootstrapTable.prototype.check = function (index) {
@@ -1531,6 +1568,33 @@
         this.updateSelected();
         this.trigger(checked ? 'check' : 'uncheck', this.data[index]);
     };
+    
+    BootstrapTable.prototype.checkBy = function (obj) {
+        this.checkBy_(true, obj);
+    };
+
+    BootstrapTable.prototype.uncheckBy = function (obj) {
+        this.checkBy_(false, obj);
+    };
+    
+    BootstrapTable.prototype.checkBy_ = function (checked, obj) {
+        if(!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
+            return;
+        }
+        
+        var that = this;
+        $.each(this.options.data, function (index, row) {
+            if (!row.hasOwnProperty(obj.field)) {
+                return false;
+            }
+            if ($.inArray(row[obj.field], obj.values) !== -1) {
+                that.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
+                row[that.header.stateField] = checked;
+                that.trigger(checked ? 'check' : 'uncheck', row);  
+            }
+        });
+        this.updateSelected();
+    };
 
     BootstrapTable.prototype.destroy = function () {
         this.$el.insertBefore(this.$container);
@@ -1632,6 +1696,7 @@
         'mergeCells',
         'checkAll', 'uncheckAll',
         'check', 'uncheck',
+        'checkBy', 'uncheckBy',
         'refresh',
         'resetView',
         'destroy',

+ 5 - 3
src/extensions/flatJSON/bootstrap-table-flatJSON.js

@@ -45,11 +45,13 @@
     BootstrapTable.prototype.initData = function () {
 
         _initData.apply(this, Array.prototype.slice.apply(arguments));
-        var that = this;
 
         //If the flat is true
-        if (that.options.flat) {
-            that.options.data = sd.flatHelper(that.options.data);
+        if (this.options.flat) {
+            this.options.data = sd.flatHelper(this.options.data);
+        }
+        if (this.options.sidePagination === 'server') {
+            this.data = this.options.data;
         }
     };