浏览代码

Add row data to sorter function

zhixin 8 年之前
父节点
当前提交
70efbda28c

+ 3 - 1
docs/_i18n/en/documentation/column-options.md

@@ -212,7 +212,9 @@ function formatter(value, row, index, field) {
         <td>
         <td>
         The custom field sort function that used to do local sorting, take two parameters: <br>
         The custom field sort function that used to do local sorting, take two parameters: <br>
         a: the first field value.<br>
         a: the first field value.<br>
-        b: the second field value.
+        b: the second field value.<br>
+        rowA: the first row.<br>
+        rowB: the second row.
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>

+ 4 - 1
docs/_i18n/es/documentation/column-options.md

@@ -197,7 +197,10 @@ Las propiedades de la columna están definidas en `jQuery.fn.bootstrapTable.colu
         <td>
         <td>
         La función sort es usada para hacer el ordenamiendo customizable, toma dos parámetros: <br>
         La función sort es usada para hacer el ordenamiendo customizable, toma dos parámetros: <br>
         a: el primer valor del campo.<br>
         a: el primer valor del campo.<br>
-        b: el segundo valor del campo.</td>
+        b: el segundo valor del campo.<br>
+        rowA: la primera fila.<br>
+        rowB: la segunda fila.
+        </td>
     </tr>
     </tr>
     <tr>
     <tr>
         <td>sortName</td>
         <td>sortName</td>

+ 3 - 1
docs/_i18n/zh-cn/documentation/column-options.md

@@ -199,7 +199,9 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
         <td>
         <td>
         The custom field sort function that used to do local sorting, take two parameters: <br>
         The custom field sort function that used to do local sorting, take two parameters: <br>
         a: the first field value.<br>
         a: the first field value.<br>
-        b: the second field value.
+        b: the second field value.<br>
+        rowA: the first row.<br>
+        rowB: the second row.
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>

+ 11 - 8
src/bootstrap-table.js

@@ -604,7 +604,9 @@
         if (this.options.locale) {
         if (this.options.locale) {
             var parts = this.options.locale.split(/-|_/);
             var parts = this.options.locale.split(/-|_/);
             parts[0].toLowerCase();
             parts[0].toLowerCase();
-            if (parts[1]) parts[1].toUpperCase();
+            if (parts[1]) {
+                parts[1].toUpperCase();
+            }
             if ($.fn.bootstrapTable.locales[this.options.locale]) {
             if ($.fn.bootstrapTable.locales[this.options.locale]) {
                 // locale as requested
                 // locale as requested
                 $.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]);
                 $.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]);
@@ -727,9 +729,11 @@
                 var $this = $(this),
                 var $this = $(this),
                     cspan = +$this.attr('colspan') || 1,
                     cspan = +$this.attr('colspan') || 1,
                     rspan = +$this.attr('rowspan') || 1,
                     rspan = +$this.attr('rowspan') || 1,
-                    tx, ty;
+                    tx,
+                    ty;
 
 
-                for (; m[y] && m[y][x]; x++); //skip already occupied cells in current row
+                // skip already occupied cells in current row
+                for (; m[y] && m[y][x]; x++);
 
 
                 for (tx = x; tx < x + cspan; tx++) { //mark matrix elements occupied by current cell with true
                 for (tx = x; tx < x + cspan; tx++) { //mark matrix elements occupied by current cell with true
                     for (ty = y; ty < y + rspan; ty++) {
                     for (ty = y; ty < y + rspan; ty++) {
@@ -976,7 +980,7 @@
                 }
                 }
                 var aa = getItemField(a, name, that.options.escape),
                 var aa = getItemField(a, name, that.options.escape),
                     bb = getItemField(b, name, that.options.escape),
                     bb = getItemField(b, name, that.options.escape),
-                    value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
+                    value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb, a, b]);
 
 
                 if (value !== undefined) {
                 if (value !== undefined) {
                     if (that.options.sortStable && value === 0) {
                     if (that.options.sortStable && value === 0) {
@@ -2603,9 +2607,8 @@
             return;
             return;
         }
         }
 
 
-        this.columns[this.fieldsColumnsIndex[params.field]].title = this.options.escape
-                                                                    ? escapeHTML(params.title)
-                                                                    : params.title;
+        this.columns[this.fieldsColumnsIndex[params.field]].title =
+            this.options.escape ? escapeHTML(params.title) : params.title;
 
 
         if (this.columns[this.fieldsColumnsIndex[params.field]].visible) {
         if (this.columns[this.fieldsColumnsIndex[params.field]].visible) {
             var header = this.options.height !== undefined ? this.$tableHeader : this.$header;
             var header = this.options.height !== undefined ? this.$tableHeader : this.$header;
@@ -2755,7 +2758,7 @@
             if (rowId === -1) {
             if (rowId === -1) {
                 return;
                 return;
             }
             }
-            that.data[rowId][params.field] = params.value
+            that.data[rowId][params.field] = params.value;
         });
         });
 
 
         if (params.reinit === false) {
         if (params.reinit === false) {