浏览代码

Added sort routine for adding items to select

Items are placed in the selects in the order they are found in the data.

This fix sorts the options as they are added to the select element
Troy Morehouse 10 年之前
父节点
当前提交
e0765ae0d5
共有 1 个文件被更改,包括 16 次插入0 次删除
  1. 16 0
      src/extensions/filter-control/bootstrap-table-filter-control.js

+ 16 - 0
src/extensions/filter-control/bootstrap-table-filter-control.js

@@ -67,6 +67,22 @@
             selectControl.append($("<option></option>")
             selectControl.append($("<option></option>")
                 .attr("value", value)
                 .attr("value", value)
                 .text($('<div />').html(text).text()));
                 .text($('<div />').html(text).text()));
+            // Sort it. Not overly efficient to do this here
+            var $opts = selectControl.find('option:gt(0)');
+            $opts.sort(function(a,b){
+                a = $(a).text().toLowerCase();
+                b = $(b).text().toLowerCase();
+                if (a === undefined || a === null) { a = ''; }
+                if (b === undefined || b === null) { b = ''; }
+                if ($.isNumeric(a) && $.isNumeric(b)) {
+                    // Convert numerical values from string to float.
+                    a = parseFloat(a);
+                    b = parseFloat(b);
+                }
+                return a > b ? 1 : a < b ? -1 : 0;
+            });
+			selectControl.find('option:gt(0)').remove();
+			selectControl.append($opts);
         }
         }
     };
     };