浏览代码

Fix #85: Select row and add row class.

zhixin 11 年之前
父节点
当前提交
088b860263
共有 2 个文件被更改,包括 18 次插入3 次删除
  1. 2 1
      src/bootstrap-table.css
  2. 16 2
      src/bootstrap-table.js

+ 2 - 1
src/bootstrap-table.css

@@ -66,8 +66,9 @@
     border-left: none;
 }
 
+/* the same color with .active */
 .fixed-table-container tbody .selected td {
-    background-color: #d9edf7;
+    background-color: #f5f5f5;
 }
 
 .fixed-table-container .bs-checkbox {

+ 16 - 2
src/bootstrap-table.js

@@ -843,8 +843,14 @@
         this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
         this.$selectItem.off('click').on('click', function (event) {
             event.stopImmediatePropagation();
+
+            // radio trigger click event bug!
+            if ($(this).is(':radio')) {
+                $(this).prop('checked', true);
+            }
+
             var checkAll = that.$selectItem.length === that.$selectItem.filter(':checked').length,
-                checked = $(this).prop('checked') || $(this).is(':radio'),
+                checked = $(this).prop('checked'),
                 row = that.data[$(this).data('index')];
 
             that.$selectAll.add(that.$selectAll_).prop('checked', checkAll);
@@ -858,7 +864,7 @@
                 that.$selectItem.filter(':checked').not(this).prop('checked', false);
             }
 
-//            $(this).parents('tr')[checked ? 'addClass' : 'removeClass']('selected');
+            that.updateSelected();
         });
 
         $.each(this.header.events, function (i, events) {
@@ -959,6 +965,12 @@
             '</span>'].join('');
     };
 
+    BootstrapTable.prototype.updateSelected = function () {
+        this.$selectItem.each(function () {
+            $(this).parents('tr')[$(this).prop('checked') ? 'addClass' : 'removeClass']('selected');
+        });
+    };
+
     BootstrapTable.prototype.updateRows = function (checked) {
         var that = this;
 
@@ -1132,6 +1144,7 @@
         this.$selectAll.add(this.$selectAll_).prop('checked', true);
         this.$selectItem.prop('checked', true);
         this.updateRows(true);
+        this.updateSelected();
         this.trigger('check-all');
     };
 
@@ -1139,6 +1152,7 @@
         this.$selectAll.add(this.$selectAll_).prop('checked', false);
         this.$selectItem.prop('checked', false);
         this.updateRows(false);
+        this.updateSelected();
         this.trigger('uncheck-all');
     };