Browse Source

Add COLUMN_DEFAULTS.

zhixin 11 years ago
parent
commit
ca7e35bb26
1 changed files with 21 additions and 3 deletions
  1. 21 3
      src/bootstrap-table.js

+ 21 - 3
src/bootstrap-table.js

@@ -107,6 +107,21 @@
         onLoadError: function(status) {return false;}
         onLoadError: function(status) {return false;}
     };
     };
 
 
+    BootstrapTable.COLUMN_DEFAULTS = {
+        radio: false,
+        checkbox: false,
+        field: undefined,
+        title: undefined,
+        align: undefined, // left, right, center
+        valign: undefined, // top, middle, bottom
+        width: undefined,
+        sortable: true,
+        order: 'asc', // asc, desc
+        visible: true,
+        formatter: undefined,
+        sorter: undefined
+    };
+
     BootstrapTable.prototype.init = function() {
     BootstrapTable.prototype.init = function() {
         this.initContainer();
         this.initContainer();
         this.initHeader();
         this.initHeader();
@@ -172,11 +187,13 @@
             sorters: []
             sorters: []
         };
         };
         $.each(this.options.columns, function(i, column) {
         $.each(this.options.columns, function(i, column) {
+            column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, column);
+
             var text = '',
             var text = '',
-                style = sprintf('text-align: %s; ', column.align) + sprintf('vertical-align: %s; ', column.valign),
-                order = that.options.sortOrder || column.order || 'asc';
+                style = sprintf('text-align: %s; ', column.align)
+                    + sprintf('vertical-align: %s; ', column.valign),
+                order = that.options.sortOrder || column.order;
 
 
-            column.visible = typeof column.visible === 'undefined' ? true : column.visible;
             if (!column.visible) {
             if (!column.visible) {
                 return;
                 return;
             }
             }
@@ -813,6 +830,7 @@
 
 
     $.fn.bootstrapTable.Constructor = BootstrapTable;
     $.fn.bootstrapTable.Constructor = BootstrapTable;
     $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
     $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
+    $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
 
 
     // BOOTSTRAP TABLE INIT
     // BOOTSTRAP TABLE INIT
     // =======================
     // =======================