Improve table filtering, use keyup, improve alternating row background
authorJoey Schulze <joey@infodrom.org>
Tue, 11 Jul 2017 21:29:43 +0000 (23:29 +0200)
committerJoey Schulze <joey@infodrom.org>
Tue, 11 Jul 2017 21:29:43 +0000 (23:29 +0200)
src/InfoCon/stempel/status.wml

index 4497d1c..af5233b 100644 (file)
@@ -310,19 +310,22 @@ function filter_change(e)
     var form = $(this).attr('id').split('_')[1];
     var filter = $('input#filter_'+form).val();
 
+    var cnum = 0;
     $('table#table_'+form+' tbody tr').each(function(i,e){
        if (filter.length) {
            var td = $(this).find('td:nth-child(4)');
-           if (td.text().toLowerCase().indexOf(filter) > -1)
-               $(this).show();
-           else {
+           if (td.text().toLowerCase().indexOf(filter) > -1) {
+               $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
+               cnum = cnum ? 0 : 1;
+           } else {
                if ($(this).find('input[type="checkbox"]').prop('checked')) {
                    toggle_checkbox(form, td);
                }
                $(this).hide();
            }
        } else {
-           $(this).show();
+           $(this).removeClass('t0').removeClass('t1').addClass('t'+cnum).show();
+           cnum = cnum ? 0 : 1;
        }
     });
 }
@@ -330,11 +333,11 @@ function filter_change(e)
 function filter_clear(e)
 {
     var form = $(this).attr('id').split('_')[1];
-    $('div.jscode input.filter#filter_'+form).val('').change();
+    $('div.jscode input.filter#filter_'+form).val('').keyup();
 }
 
 $(function(){
-    $('div.jscode input.filter').change(filter_change);
+    $('div.jscode input.filter').keyup(filter_change);
     $('div.jscode img.filter').click(filter_clear);
 });
 </protect>