Refresh table with filter using jquery

-1

Good morning I'm looking for solutions to a demand, but I only found in php . I am new to Jquery , Ajax ... I am trying to put the filter in my table to be dynamic as the user is typing data will appear, I searched a function called autocomplete , but could not implement .

My Table.

 <table cellpadding="1" border="0" id="minhaTabela" class="table table-condensed" cellspacing="0" width="100%" >
   <thead class="fixedHeader">
     <tr bgcolor="${cortop}">
       <th width="20">&nbsp;</th>
       <th width="70">Prontu&aacute;rio</th>
       <th width="269"><b>pacientes</b></th>
       <th width="181"><b>Plano</b></th>
     </tr>
   </thead>
   <c:forEach var="item" items="${pacientes}">
     <tr bgcolor="#F4F4F4" title="${item.titlo}">
       <td >
         <input type="radio" name="radio" id="radio" value="radio" onclick="selecionar('${item.cargo}', ${item.id}, '${item.plano}', ${item.idPlano}, '<%=request.getParameter("tipo")%>')" ondblclick="selecionar2('${item.cargo}', ${item.id}, '${item.plano}', ${item.idPlano}, '<%=request.getParameter("tipo")%>')" />
       </td>
       <td>${item.id}</td>
       <td nowrap="nowrap">${item.nome}&nbsp;&nbsp;&nbsp;</td>
       <td nowrap="nowrap">${item.plano}</td>
     </tr>
   </c:forEach></table>

Through this filter I'm pulling the DB data

<label  id="lbl" style="background: ${cortop}; color: ${corletra}" class="label label-info" >Nome:</label>
<input name="jtpaciente" type="text" class="form-control" id="jtpaciente"  value="<%=request.getAttribute("paci")%>" size="74" />

When the user types and presses enter then a submit of the page is made bringing only the filtered name. Would you have a solution to add this jquery or ajax to this table em jsp ??

    
asked by anonymous 21.02.2017 / 15:34

1 answer

1

I found this solution link

<script type="text/javascript">

                                            var $rows = $('#minhaTabela tr');
                                            $('#jtpaciente').keyup(function() {

                                                var val = '^(?=.*\b' + $.trim($(this).val()).split(/\s+/).join('\b)(?=.*\b') + ').*$',
                                                    reg = RegExp(val, 'i'),
                                                    text;

                                                $rows.show().filter(function() {
                                                    text = $(this).text().replace(/\s+/g, ' ');
                                                    return !reg.test(text);
                                                }).hide();
                                            });

                                        </script>
    
22.02.2017 / 19:21