使用jquery仅从表中的一列中筛选多个值


Filter multiple values with jquery from only one column in table

我想使用jquery过滤表中的特定列,使用多选,用户可以在其中选择多个值。以下是HTML和PHP代码:

<table id="simple-table" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th>Codice Pezzo</th>
                <th>Descrizione</th>
                <th class="center">Fornitore
                <div class="col-sm-12">
                    <select multiple="multiple" class="chosen-select form-control tag-input-style" id="fornitore-select" data-placeholder="Scegli un fornitore..." name="fornitore[]"><option value="">  </option><?php
            // esecuzione della query
            $query_fornitore = "SELECT p.Marca FROM pezzi p INNER JOIN distinte d ON (d.ID_Pezzo = p.ID_Pezzo) INNER JOIN ordini o ON (o.ID_Impianto = d.ID_Impianto) WHERE o.Data_Consegna >= '".$_GET["data1"]."' AND o.Data_Consegna <= '".$_GET["data2"]."' AND o.Elaborato = 0 GROUP BY p.Marca;";
            $result_fornitore = @mysqli_query($conn, $query_fornitore);
            // controllo sul numero dei record coinvolti
            if(@mysqli_num_rows($result_fornitore)!=0)
            {
              // risultato sotto forma di array asscociativo
              while($row_fornitore = mysqli_fetch_array($result_fornitore, MYSQLI_ASSOC))
              {
                echo "<option value='"".$row_fornitore["Marca"]."'">".$row_fornitore["Marca"]."</option>";
              }
            }
            ?></select>
            </div>
                </th>
                <th>Quantità</th>
            </tr>
        </thead>
        <tbody id="body-fornitore">
            <?php
            if(isset($_GET["ordini_materiali"]) && isset($_GET["data1"]) && isset($_GET["data2"])):
                $query_distinta = "SELECT d.ID_Pezzo, p.Descrizione, p.Marca, SUM(d.Quantita), o.Quantita FROM ordini o INNER JOIN distinte d ON (d.ID_Impianto = o.ID_Impianto) INNER JOIN pezzi p ON (p.ID_Pezzo = d.ID_Pezzo) WHERE o.Data_Consegna >= '".$_GET["data1"]."' AND o.Data_Consegna <= '".$_GET["data2"]."' AND o.Elaborato = 0 GROUP BY p.ID_Pezzo;";
                $result_distinta = @mysqli_query($conn, $query_distinta);
                while($row_distinta = mysqli_fetch_array($result_distinta)): ?>
                <tr>
                    <td><?php echo $row_distinta[0]; ?></td>
                    <td><?php echo $row_distinta[1]; ?></td>
                    <td class="row-fornitore"><?php echo $row_distinta[2]; ?></td>
                    <td><?php echo number_format($row_distinta[3]*$row_distinta[4],2,",","."); ?></td>
                </tr>
            <?php endwhile; endif; ?>
        </tbody>
    </table>

这是Jquery代码:

$(document).ready(function () {
        $('#fornitore-select').change(function () {
            var valore = $(this).val() + '';
            //console.log(valore);
            if(valore == null + '')
            {
                $('#body-fornitore tr').show();
            }
            else
            {
                $('#body-fornitore tr').hide();
                $.each(valore.split(","), function(index, item) {
                    var rex = new RegExp(item, 'i');
                    $('#body-fornitore tr').filter(function () {
                        return rex.test($(this).text());
                    }).show();
                });
            }
        });
    });

使用这种方法,当我选择多个选项时,过滤器会考虑表中的所有列,我只想过滤一个(第三个)。有办法吗?我快疯了!!

您正在处理:

#body-fornitore tr

这意味着当你想处理第三列时,所有的行,也就是:

.row-fornitore

问候