浏览代码

Added Group-By extension

Dennis Hernández 10 年之前
父节点
当前提交
4f20a7c9d1

+ 2 - 2
docs/_i18n/es/documentation/column-options.md

@@ -67,14 +67,14 @@ Las propiedades de la columna están definidas en `jQuery.fn.bootstrapTable.colu
         <td>rowspan / data-rowspan</td>
         <td>Number</td>
         <td>undefined</td>
-        <td>Indicate how many rows a cell should take up.</td>
+        <td>Indica cuantas filas debe tomar una celda.</td>
     </tr>
     <tr>
         <td>colspan</td>
         <td>colspan / data-colspan</td>
         <td>Number</td>
         <td>undefined</td>
-        <td>Indicate how many columns a cell should take up.</td>
+        <td>indica cuantas columnas debe tomar una celda.</td>
     </tr>
     <tr>
         <td>align</td>

+ 31 - 0
src/extensions/group-by/README.md

@@ -0,0 +1,31 @@
+# Table group-by
+
+Use Plugin: [bootstrap-table-group-by](https://github.com/djhvscf/bootstrap-table-group-by) </br>
+Dependence: [jquery-treetable](https://github.com/ludo/jquery-treetable/) v3.2.0 </br>
+You must include the bootstrap-table-group-by.css file in order to get the appropriate style
+
+## Usage
+
+```html
+<script src="extensions/group-by/bootstrap-table-group-by.js"></script>
+```
+
+## Options
+
+### groupBy
+
+* type: Boolean
+* description: Set true to group the data by the field passed.
+* default: `false`
+
+### groupByField
+
+* type: String
+* description: Set the field that you want to group the data.
+* default: ``
+
+## Known issues
+
+### OnSort
+
+* When sort options are set to True the group by is not working properly, for now if these properties are set to True the group by extension will be disabled.

文件差异内容过多而无法显示
+ 53 - 0
src/extensions/group-by/bootstrap-table-group-by.css


+ 25 - 79
src/extensions/group-by/bootstrap-table-group-by.js

@@ -124,93 +124,39 @@
         _initData = BootstrapTable.prototype.initData;
 
     BootstrapTable.prototype.init = function () {
-        if ((this.options.groupBy) && (this.options.groupByField !== '')) {
-            var that = this;
+        //Temporal validation
+        if (!this.options.sortName) {
+            if ((this.options.groupBy) && (this.options.groupByField !== '')) {
+                var that = this;
+
+                // Compatibility: IE < 9 and old browsers
+                if (!Object.keys) {
+                    setObjectKeys();
+                }
 
-            // Compatibility: IE < 9 and old browsers
-            if (!Object.keys) {
-                setObjectKeys();
-            }
+                //Make sure that the internal variables are set correctly
+                this.options.loaded = false;
+                this.options.originalData = undefined;
 
-            //Make sure that the internal variables are set correctly
-            this.options.loaded = false;
-            this.options.originalData = undefined;
-
-            originalRowAttr = this.options.rowAttributes;
-            this.options.rowAttributes = rowAttr;
-            this.$el.on('post-body.bs.table', function () {
-                that.$el.treetable({
-                    expandable: true
-                }, true);
-            });
+                originalRowAttr = this.options.rowAttributes;
+                this.options.rowAttributes = rowAttr;
+                this.$el.on('post-body.bs.table', function () {
+                    that.$el.treetable({
+                        expandable: true
+                    }, true);
+                });
+            }
         }
         _init.apply(this, Array.prototype.slice.apply(arguments));
     };
 
     BootstrapTable.prototype.initData = function () {
-        if ((this.options.groupBy) && (this.options.groupByField !== '')) {
-            makeGrouped(this);
+        //Temporal validation
+        if (!this.options.sortName) {
+            if ((this.options.groupBy) && (this.options.groupByField !== '')) {
+                makeGrouped(this);
+            }
         }
-
         _initData.apply(this, Array.prototype.slice.apply(arguments));
     };
-
-    /*BootstrapTable.prototype.initSort = function () {
-        var that = this,
-            name = this.options.sortName,
-            order = this.options.sortOrder === 'desc' ? -1 : 1,
-            index = $.inArray(this.options.sortName, this.header.fields);
-
-        if (index !== -1) {
-            this.data.sort(function (a, b) {
-                if ((a.IsParent) || (b.IsParent)) {
-                    return order;
-                }
-                if (that.header.sortNames[index]) {
-                    name = that.header.sortNames[index];
-                }
-                var aa = a[name],
-                    bb = b[name],
-                    value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
-
-                if (value !== undefined) {
-                    return order * value;
-                }
-
-                // Fix #161: undefined or null string sort bug.
-                if (aa === undefined || aa === null) {
-                    aa = '';
-                }
-                if (bb === undefined || bb === null) {
-                    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;
-                    }
-                    return order;
-                }
-
-                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;
-                }
-
-                return order;
-            });
-        }
-    };*/
 }(jQuery);