Browse Source

Hi,

You can send me a pull request, and if the feature is good I will consider to merge it to the develop version. Thanks.

https://github.com/wenzhixin/bootstrap-table/pulls

--
Best regards,
Zhixin Wen
China

2015-02-26 21:14 GMT+08:00 Yuanyan Wu <ywu999@hotmail.com>:
Hi, Wen Zhi Xin,
 
Your script was very helpful for me. I found out an extra feature that could be added into it. Basically I wanted to sort a column with a customizable sort-name, not the default sort-name in the header, or the field of the column. This feature is very useful for the following scenario:
 
I have a column field “name” with the value of abc, but I want to display in html (field name: htmlName) as “<b><span style=”color:red”>abc</span></b>”. I really want to sort the column use the field “name” instead of “htmlName”.
 
If you are willing, I can commit my changes to your project.
 
Thanks,
 
Yuanyan Wu
Yuanyan Wu 11 years ago
parent
commit
9ae2428d37
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/bootstrap-table.js

+ 6 - 0
src/bootstrap-table.js

@@ -309,6 +309,7 @@
         footerFormatter: undefined,
         events: undefined,
         sorter: undefined,
+        sortName: undefined,
         cellStyle: undefined,
         searchable: true,
         cardVisible: true
@@ -437,6 +438,7 @@
             formatters: [],
             events: [],
             sorters: [],
+            sortNames: [],
             cellStyles: [],
             clickToSelects: [],
             searchables: []
@@ -470,6 +472,7 @@
             that.header.formatters.push(column.formatter);
             that.header.events.push(column.events);
             that.header.sorters.push(column.sorter);
+            that.header.sortNames.push(column.sortName);
             that.header.cellStyles.push(column.cellStyle);
             that.header.clickToSelects.push(column.clickToSelect);
             that.header.searchables.push(column.searchable);
@@ -638,6 +641,9 @@
 
         if (index !== -1) {
             this.data.sort(function (a, b) {
+                if(that.header.sortNames[index]) {
+                	name = that.header.sortNames[index];
+                }            	
                 var aa = a[name],
                     bb = b[name],
                     value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);