Browse Source

Merge pull request #67 from nikolas/preserve-column-classes

Preserve classes when connecting to a transformed table
文翼 11 years ago
parent
commit
147e812111
2 changed files with 24 additions and 3 deletions
  1. 1 1
      dist/bootstrap-table.min.js
  2. 23 2
      src/bootstrap-table.js

File diff suppressed because it is too large
+ 1 - 1
dist/bootstrap-table.min.js


+ 23 - 2
src/bootstrap-table.js

@@ -220,7 +220,12 @@
         this.$el.find('tbody tr').each(function () {
             var row = {};
             $(this).find('td').each(function (i) {
-                row[that.options.columns[i].field] = $(this).html();
+                var value = $(this).html();
+                var classes = $(this).attr('class') || '';
+                row[that.options.columns[i].field] = {
+                    'value': value,
+                    'class': classes
+                };
             });
             data.push(row);
         });
@@ -336,6 +341,16 @@
                 if (typeof sorter === 'string') {
                     return order * eval(sorter + '(a[name], b[name])'); // eval ?
                 }
+
+                if (typeof a === 'object' && typeof b === 'object') {
+                    if (a[name].value === b[name].value) {
+                        return 0;
+                    }
+                    if (a[name].value < b[name].value) {
+                        return order * -1;
+                    }
+                }
+
                 if (a[name] === b[name]) {
                     return 0;
                 }
@@ -711,6 +726,12 @@
                         '</td>'].join('');
                 } else {
                     value = typeof value === 'undefined' ? that.options.undefinedText : value;
+                    var classes = '';
+
+                    if (typeof value == 'object') {
+                        classes = value['class'];
+                        value = value.value;
+                    }
 
                     text = that.options.cardView ?
                         ['<div class="card-view">',
@@ -718,7 +739,7 @@
                                 getPropertyFromOther(that.options.columns, 'field', 'title', field)),
                             sprintf('<span class="value">%s</span>', value),
                             '</div>'].join('') :
-                        [sprintf('<td %s>', style),
+                        [sprintf('<td %s class="%s">', style, classes),
                             value,
                             '</td>'].join('');
                 }