sorting the brands search dropdown
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 14 Apr 2017 20:24:35 +0000 (16:24 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 14 Apr 2017 20:24:35 +0000 (16:24 -0400)
using js to sort the brands list before it is converted with asmSelect
for now, tried a few smarty methods that didn't work, will need to look
into a php method to reduce front end overhead

glm-member-db/views/front/members/list.html

index 5b53f8c..ae1405f 100644 (file)
 
     <script type="text/javascript">
         jQuery(document).ready(function($) {
-
+            
         function getParameterByName(name, url) {
             if (!url) {
               url = window.location.href;
             }
         }
 
+
+
+
+
 
 
         $('.glm-member-list-record').each(function(){
             $(this).css("display", "block");
 
         });
-$(window).on("load", function(){
-    
 
         var cat_ids     = [];
         var selected_brands = [];
@@ -470,14 +473,18 @@ $(window).on("load", function(){
                        brands.push(item);
                    }
                 });
-         });
-
+            
+            });
 
             $.each(brands, function(index, item){
                 {literal} var option = $('<option>', {value: item.id, text: item.name}); {/literal}
                 $('#brands').append(option);
 
             });
+                
+            $("#brands").html($('#brands option').sort(function(x, y) {
+                  return $(x).text() < $(y).text() ? -1 : 1;
+               }));
 
             $('#brands').prev().prev().remove();
             $('#brands').prev().remove();
@@ -485,7 +492,8 @@ $(window).on("load", function(){
 
             if( $('#brands').prev().children('li').length <= 0 ){
                 $("#rvManufacturers").prev().prev().prop('disabled', false);
-            }
+            } 
+            
         });
 
         $('#brands').on("change", function(){
@@ -507,7 +515,7 @@ $(window).on("load", function(){
                     $("#rvManufacturers").prev().prev().prop("disabled",false);
                 }
         });
-         console.log($('#rvManufacturers').find(":selected").length);
+       
         if(  $('#rvManufacturers').find(":selected").length > 0 ){
 
             var brand_ids = $('#brands').val();
@@ -545,9 +553,14 @@ $(window).on("load", function(){
             $('#brands').prev().prev().remove();
             $('#brands').prev().remove();
         }
+                   
+         $("#brands").html($('#brands option').sort(function(x, y) {
+              return $(x).text() < $(y).text() ? -1 : 1;
+           }));
+
 
     jQuery('select[multiple]').asmSelect();
-        });
+     
 
             // Show search filters box
             {if $settings.list_show_search}