Browse Source

Merge pull request #636 from ywu999/master

Customize sort field of the column
文翼 10 years ago
parent
commit
91668db4da

+ 10 - 0
docs/_i18n/en/documentation/column-options.md

@@ -180,6 +180,16 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
+        <td>sortName</td>
+        <td>data-sort-name</td>
+        <td>String</td>
+        <td>undefined</td>
+        <td>Provide a customizable sort-name, not the default sort-name in the header, or the field name
+        of the column. For example, a column might display the value of fieldName of "html" such as  
+        "&lt;b&gt;&lt;span style="color:red"&gt;abc&lt;/span&gt;&lt;/b&gt;", but a fieldName to sort is "content" with the value of "abc".
+        </td>
+    </tr>    
+    <tr>
         <td>cellStyle</td>
         <td>cellStyle</td>
         <td>data-cell-style</td>
         <td>data-cell-style</td>
         <td>Function</td>
         <td>Function</td>

+ 10 - 0
docs/_i18n/es/documentation/column-options.md

@@ -177,6 +177,16 @@ Las propiedades de la columna están definidas en `jQuery.fn.bootstrapTable.colu
         b: el segundo valor del campo.</td>
         b: el segundo valor del campo.</td>
     </tr>
     </tr>
     <tr>
     <tr>
+        <td>sortName</td>
+        <td>data-sort-name</td>
+        <td>String</td>
+        <td>undefined</td>
+        <td>Proporcionar una especie-nombre adaptable, no la clase-nombre por defecto en la cabecera, o el nombre del campo
+         de la columna. Por ejemplo, una columna puede mostrar el valor de nombreCampo de "HTML" como
+         "&lt;b&gt;&lt;span style="color:red"&gt;abc&lt;/span&gt;&lt;/b&gt;", pero una nombreCampo para ordenar es el "contenido" con el valor de "abc".
+        </td>
+    </tr>    
+    <tr>
         <td>cellStyle</td>
         <td>cellStyle</td>
         <td>data-cell-style</td>
         <td>data-cell-style</td>
         <td>Function</td>
         <td>Function</td>

+ 10 - 0
docs/_i18n/zh-cn/documentation/column-options.md

@@ -154,6 +154,16 @@ The column options is defined in `jQuery.fn.bootstrapTable.columnDefaults`.
         </td>
         </td>
     </tr>
     </tr>
     <tr>
     <tr>
+        <td>sortName</td>
+        <td>data-sort-name</td>
+        <td>String</td>
+        <td>undefined</td>
+        <td>Provide a customizable sort-name, not the default sort-name in the header, or the field name
+        of the column. For example, a column might display the value of fieldName of "html" such as  
+        "&lt;b&gt;&lt;span style="color:red"&gt;abc&lt;/span&gt;&lt;/b&gt;", but a fieldName to sort is "content" with the value of "abc".
+        </td>
+    </tr>  
+    <tr>
         <td>cellStyle</td>
         <td>cellStyle</td>
         <td>data-cell-style</td>
         <td>data-cell-style</td>
         <td>Function</td>
         <td>Function</td>

+ 6 - 0
src/bootstrap-table.js

@@ -329,6 +329,7 @@
         footerFormatter: undefined,
         footerFormatter: undefined,
         events: undefined,
         events: undefined,
         sorter: undefined,
         sorter: undefined,
+        sortName: undefined,
         cellStyle: undefined,
         cellStyle: undefined,
         searchable: true,
         searchable: true,
         cardVisible: true,
         cardVisible: true,
@@ -466,6 +467,7 @@
             formatters: [],
             formatters: [],
             events: [],
             events: [],
             sorters: [],
             sorters: [],
+            sortNames: [],
             cellStyles: [],
             cellStyles: [],
             clickToSelects: [],
             clickToSelects: [],
             searchables: []
             searchables: []
@@ -513,6 +515,7 @@
             that.header.formatters.push(column.formatter);
             that.header.formatters.push(column.formatter);
             that.header.events.push(column.events);
             that.header.events.push(column.events);
             that.header.sorters.push(column.sorter);
             that.header.sorters.push(column.sorter);
+            that.header.sortNames.push(column.sortName);
             that.header.cellStyles.push(column.cellStyle);
             that.header.cellStyles.push(column.cellStyle);
             that.header.clickToSelects.push(column.clickToSelect);
             that.header.clickToSelects.push(column.clickToSelect);
             that.header.searchables.push(column.searchable);
             that.header.searchables.push(column.searchable);
@@ -657,6 +660,9 @@
 
 
         if (index !== -1) {
         if (index !== -1) {
             this.data.sort(function (a, b) {
             this.data.sort(function (a, b) {
+                if(that.header.sortNames[index]) {
+                    name = that.header.sortNames[index];
+                }            	
                 var aa = a[name],
                 var aa = a[name],
                     bb = b[name],
                     bb = b[name],
                     value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
                     value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);