Browse Source

changed context of column.formatter() to column

Prior to this change, there is no way to identify column.field
from the formatter. The context (this) of column.formatter()
was table.header. which served no practical purpose.
jtrumbull 10 years ago
parent
commit
3ce92c69cf
1 changed files with 6 additions and 4 deletions
  1. 6 4
      src/bootstrap-table.js

+ 6 - 4
src/bootstrap-table.js

@@ -952,11 +952,13 @@
             this.data = s ? $.grep(this.data, function (item, i) {
             this.data = s ? $.grep(this.data, function (item, i) {
                 for (var key in item) {
                 for (var key in item) {
                     key = $.isNumeric(key) ? parseInt(key, 10) : key;
                     key = $.isNumeric(key) ? parseInt(key, 10) : key;
-                    var value = item[key];
+                    var value = item[key],
+                        column = that.options.columns[getFieldIndex(that.options.columns, key)],
+                        j = $.inArray(key, that.header.fields);
 
 
                     // Fix #142: search use formated data
                     // Fix #142: search use formated data
-                    value = calculateObjectValue(that.header,
-                        that.header.formatters[$.inArray(key, that.header.fields)],
+                    value = calculateObjectValue(column,
+                        that.header.formatters[j],
                         [value, item, i], value);
                         [value, item, i], value);
 
 
                     var index = $.inArray(key, that.header.fields);
                     var index = $.inArray(key, that.header.fields);
@@ -1290,7 +1292,7 @@
 
 
                 style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
                 style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
 
 
-                value = calculateObjectValue(that.header,
+                value = calculateObjectValue(column,
                     that.header.formatters[j], [value, item, i], value);
                     that.header.formatters[j], [value, item, i], value);
 
 
                 // handle td's id and class
                 // handle td's id and class