Advertisement
Guest User

UserSpice User Search

a guest
Sep 7th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     //var activeSystemClass = $('.list-group-item.active');
  3.     // affect all table rows on in systems table
  4.     var tableBody = $('.table-list-search tbody');
  5.     var tableRowsClass = $('.table-list-search tbody tr');
  6.  
  7.     //something is entered in search form
  8.     $('#system-search').keyup( function() {
  9.        var that = this;
  10.         $('.search-sf').remove();
  11.         tableRowsClass.each( function(i, val) {
  12.             //Lower text for case insensitive
  13.             var rowText = $(val).text().toLowerCase();
  14.             var inputText = $(that).val().toLowerCase();
  15.             if(inputText != '')
  16.             {
  17.                 $('.search-query-sf').remove();
  18.                 $('.alluinfo').html('<strong class="text-success">Searching for: "'+ $(that).val() + '"</strong>');
  19.             }
  20.             else
  21.             {
  22.                 $('.search-query-sf').remove();
  23.                 $('.alluinfo').html('');
  24.             }
  25.  
  26.             if( rowText.indexOf( inputText ) == -1 )
  27.             {
  28.                 //hide rows
  29.                 tableRowsClass.eq(i).hide();
  30.  
  31.             }
  32.             else
  33.             {
  34.                 $('.search-sf').remove();
  35.                 tableRowsClass.eq(i).show();
  36.             }
  37.         });
  38.         //all tr elements are hidden
  39.         if(tableRowsClass.children(':visible').length == 0)
  40.         {
  41.             $('.alluinfo').append(' :: <span class="text-danger">No entries found.</span>');
  42.         }
  43.     });
  44.  
  45.     $('.reset').click(function() {
  46.         $('.search-query-sf').remove();
  47.         $('.alluinfo').html('');
  48.         $('#system-search').val('');
  49.         tableRowsClass.each( function(i, val) {
  50.             tableRowsClass.eq(i).show();
  51.         });
  52.     });
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement