Hide table rows

0

I have the following table and I would like you to click on a button to hide some rows based on a condition in the value you have

<table class="uk-table" id="mitabla">
                    <thead>
                        <tr>
                            <th>
                                Oficina
                            </th>
                            <th>
                                Numero de Oficina
                            </th>
                            <th>
                                Turno
                            </th>
                            <th>
                                Status
                            </th>
                            <th>
                                tipo de tramite
                            </th>
                            <th>
                                Acción
                            </th>
                        </tr>
                    </thead>
                    <tbody id="body_tramites">
                        <?php 
                        while ($mostrar=mysqli_fetch_row($result)) {
                        ?>
                        <tr>
                            <td><?php echo $mostrar[0]?></td>
                            <td><?php echo $mostrar[1]?></td>
                            <td><?php echo $mostrar[2]?></td>
                            <?php

                            $cron= $mostrar[3];
                            if($cron<$time){ 
                                 echo "<td class=\"verde\">".$cron."</td>" ;
                                }
                                elseif($cron>$time){ 
                                 echo "<td class=\"rojo\">".$cron."</td>" ;
                                }  ?>
                            <td><?php echo $mostrar[4]?></td>
                            <td><i data-toggle="modal" data-target="#modal_comprobacion" class="material-icons uk-text-primary md-icon uk-form-file" >search</i></td>
                        </tr>
                        <?php   
                        }
                        ?>
                    </tbody>
                </table>

I tried this:

$('#mostrarVencidos').click(function() {
    $("table tr td").each(function() {
        var tiempo = "00:00:30";
        var celda = $.trim($(this).text());
        if (celda < tiempo) {
            $(this).parent().hide();
        }
    });
});
$('#mostrarEnTiempo').click(function() {
    $("table tr td").each(function() {
        var tiempo = "00:00:30";
        var celda = $.trim($(this).text());
        if (celda > tiempo) {
            $(this).parent().hide();
        }
    });
});

WITHOUT SUCCESS: In #showthroughs if you show me correctly and in the other hide all

    
asked by arglez35 08.03.2018 в 18:07
source

1 answer

-1

It would be best to pause a numerical value to make the comparisons. Since it is not convenient to compare String with "greater or lesser than".

Create a function to obtain the second of the string (HH: MM: SS) or simply place the code directly.

function getSeconds(string) {
    var x = string.split(':');
    // Asumiendo que el formato siempre será HH:MM:SS
    var seconds = (+x[0]) * 360 + (+x[1]) * 60 + (+x[2]); 
}

$('#mostrarVencidos').click(function() {
    $("table tr td").each(function() {
        var tiempo = "00:00:30";
        var celda = $.trim($(this).text());
        if (getSeconds(celda) < getSeconds(tiempo)) {
            $(this).parent().hide();
        }
    });
});
$('#mostrarEnTiempo').click(function() {
    $("table tr td").each(function() {
        var tiempo = "00:00:30";
        var celda = $.trim($(this).text());
        if (getSeconds(celda) > getSeconds(tiempo)) {
            $(this).parent().hide();
        }
    });
});
  

However, it would be advisable to verify beforehand that the values are clearly numerical and that they exist in the function to obtain the seconds

function getSeconds(string) {
    var x = string.split(':');
    var hh = x[0] === undefined || isNaN(parseFloat(x[0])) ? 0 : parseInt(x[0]);
    var mm = x[1] === undefined || isNaN(parseFloat(x[1])) ? 0 : parseInt(x[1]);
    var ss = x[2] === undefined || isNaN(parseFloat(x[2])) ? 0 : parseInt(x[2]);
    // minutes are worth 60 seconds. Hours are worth 60 minutes.

        // Asumiendo que el formato siempre será HH:MM:SS

    var seconds = (+hh) * 360 + (+mm) * 60 + (+ss); 
    return seconds;
}
    
answered by 09.03.2018 в 12:36