Browse Source

Merge pull request #100 from himyouten/add_check_to_click_per_column

added clickToSelect to columns
文翼 11 years ago
parent
commit
0b4ebe11cd
2 changed files with 20 additions and 5 deletions
  1. 9 0
      docs/docs.js
  2. 11 5
      src/bootstrap-table.js

+ 9 - 0
docs/docs.js

@@ -533,6 +533,15 @@ $(function () {
                     description_zh: '可对列进行自定义排序,包含两个参数:<br />a: 第一个值。<br /> b: 第二个值。',
                     'default': 'undefined',
                     example: 'custom-sort-table'
+                },
+                {
+                    name: 'clickToSelect',
+                    attribute: 'data-click-to-select',
+                    type: 'Boolean',
+                    description: 'True to select checkbox or radiobox when the column is clicked.',
+                    description_zh: '设置为True时点击行即可选中单选/复选框。',
+                    'default': 'true',
+                    example: 'table-select'
                 }
             ]
         });

+ 11 - 5
src/bootstrap-table.js

@@ -172,7 +172,8 @@
         switchable: true,
         formatter: undefined,
         events: undefined,
-        sorter: undefined
+        sorter: undefined,
+		clickToSelect: true
     };
 
     BootstrapTable.EVENTS = {
@@ -275,7 +276,8 @@
             styles: [],
             formatters: [],
             events: [],
-            sorters: []
+            sorters: [],
+			clickToSelects: []
         };
         $.each(this.options.columns, function (i, column) {
             var text = '',
@@ -293,6 +295,7 @@
             that.header.formatters.push(column.formatter);
             that.header.events.push(column.events);
             that.header.sorters.push(column.sorter);
+            that.header.clickToSelects.push(column.clickToSelect);
 
             if (column.halign) {
                 style = sprintf('text-align: %s; ', column.halign) +
@@ -833,10 +836,13 @@
 
         this.$container.find('.fixed-table-body').scrollTop(0);
 
-        this.$body.find('tr').off('click').on('click', function () {
-            that.trigger('click-row', that.data[$(this).data('index')], $(this));
+		// click to select by column
+        this.$body.find('> tr > td').off('click').on('click', function () {
+			// if click to select - then trigger the checkbox/radio click
             if (that.options.clickToSelect) {
-                $(this).find(sprintf('[name="%s"]', that.options.selectItemName)).trigger('click');
+				if (that.header.clickToSelects[$(this).parent().children().index($(this))]){
+	                $(this).parent().find(sprintf('[name="%s"]', that.options.selectItemName)).trigger('click');
+				}
             }
         });
         this.$body.find('tr').off('dblclick').on('dblclick', function () {