Browse Source

Merge pull request #1085 from djhvscf/master

Added columnsHidden option in order to hide columns in cardView mode
文翼 10 years ago
parent
commit
45843d1657

+ 2 - 2
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -267,6 +267,7 @@
         onColumnSearch: function (field, text) {
             return false;
         },
+        filterShowClear: false,
         //internal variables
         values: []
     });
@@ -274,8 +275,7 @@
     $.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
         filterControl: undefined,
         filterData: undefined,
-        filterDatepickerOptions: undefined,
-        filterShowClear: false
+        filterDatepickerOptions: undefined
     });
 
     $.extend($.fn.bootstrapTable.Constructor.EVENTS, {

+ 6 - 0
src/extensions/mobile/README.md

@@ -33,3 +33,9 @@ Use Plugin: [bootstrap-table-mobile](https://github.com/wenzhixin/bootstrap-tabl
 * type: Integer
 * description: Set the minimum height when the table will change the view.
 * default: `undefined`
+
+### columnsHidden
+
+* type: String
+* description: Set the columns fields in this array in order to hide those columns in the cardView mode. Use this way in `data-*` configuration: ` data-columns-hidden="['name', 'description']"` or this way in javascript configuration: `columnsHidden = ['name', 'description']`. 
+* default: `undefined`

+ 32 - 3
src/extensions/mobile/bootstrap-table-mobile.js

@@ -8,6 +8,31 @@
 
     '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);
+                    }
+                }
+            });
+        }
+    };
+
     var resetView = function (that) {
         if (that.options.height || that.options.showFooter) {
             setTimeout(that.resetView, 1);
@@ -34,10 +59,12 @@
 
     var conditionCardView = function (that) {
         changeTableView(that, false);
+        showHideColumns(that, false);
     };
 
     var conditionFullView = function (that) {
         changeTableView(that, true);
+        showHideColumns(that, true);
     };
 
     var changeTableView = function (that, cardViewState) {
@@ -48,13 +75,14 @@
     var debounce = function(func,wait) {
         var timeout;
         return function() {
-            var context = this, args = arguments;
+            var context = this,
+                args = arguments;
             var later = function() {
                 timeout = null;
                 func.apply(context,args);
             };
             clearTimeout(timeout);
-            timeout = setTimeout(later,wait);
+            timeout = setTimeout(later, wait);
         };
     };
 
@@ -63,7 +91,8 @@
         minWidth: 562,
         minHeight: undefined,
         heightThreshold: 100, // just slightly larger than mobile chrome's auto-hiding toolbar
-        checkOnInit: true
+        checkOnInit: true,
+        columnsHidden: []
     });
 
     var BootstrapTable = $.fn.bootstrapTable.Constructor,