Capture only line

Asked

Viewed 78 times

1

I have a table created in array, and the modal button opens a table for selection of units of weight / measure, but when the selection is captured fills the whole table as in the photo below. How do I fill only the line ?

inserir a descrição da imagem aqui

Table structure opened by clicking on the modal

<table class='table table-bordered'>
   <thead>
       <tr>
           <th>  Unidade </th>
           <th>  Descrição </th>
       </tr>
   </thead>
   <tbody>
   <?php
       include ("conn.php");

       $result = "SELECT * FROM cadunid ORDER BY descricao";
       $resultado = mysqli_query($conn, $result);

       while($row = mysqli_fetch_assoc($resultado)) {
           echo "<tr class='btn-default'>";
               echo "<td class='get-value'>". $row['codigo'] ."</td>";
               echo "<td class='get-value-codigo'>". $row['descricao'] ."</td>";
           echo "</tr>";
       }                      
   ?>
   </tbody>
</table>

table structure shown in the image above

<table class="table table-bordered"><!-- Iniciando a Tabela -->
    <thead>
       <tr><!-- Início dos Títulos da Tabela / Cabeçalho -->
         <th><button type="button" class="" data-toggle="modal" data-target="#myModal">Unidade >>                 </button></th>
         <th>Preço Custo</th>
         <th>Preço Venda</th>
         <th>Peso Bruto</th>
         <th>Peso Liquido</th>
         <th>Qtd. Emb.</th>
       </tr><!-- Fim dos Títulos da Tabela / Cabeçalho -->
    </thead>

    <tbody id='prprod'><!-- Início do Corpo da tabela / Quantidade de linhas e colunas -->
    <?php for($i = 0; $i <= 5; $i++){ //coloquei este valor para testar ?>        
    <tr>                                                   
      <input type="hidden" maxlength="6"  name="recnum[]" style="border:none; width:100%; background-color: transparent;">
      <td><input type='text' name="unidad[]" class="unidade-input" style="border:none; width:100%; background-color: transparent;">                                                               
      <td><input type="text" maxlength=""  name="preco_custo[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
      <td><input type="text" maxlength=""  name="preco_venda[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
      <td><input type="text" maxlength=""  name="peso_bruto[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
      <td><input type="text" maxlength=""  name="peso_liquido[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
      <td><input type="text" maxlength=""  name="qtde_embalagem[]" placeholder="" style="border:none; width:100%; background-color: transparent;"></td>
    </tr>
     <?php } ?>
    </tbody><!-- Fim do Corpo da tabela / Quantidade de linhas e colunas -->

</table><!-- Finalizando a Tabela -->

script used to capture user-selected drive

<script>
  $(document).on('click', '.get-value', function() {
    var value = $(this).text();
    $('.close').trigger('click');
    $('.unidade-input', "tr").find.val(value); /* tentei desta forma porém continua preenchendo toda tabela */
  });

  $(document).on('click', '.get-value-codigo', function() {
      var value = $(this).siblings('.get-value').text();
      $('.close').trigger('click');
      $('.unidade-input').val(value);
  });
</script>
  • so much putting ID’s on the lines... then when filling picks up the tr with x ID

  • there is no way to put id in a loop for, it would have to be class, because ID is unique from an element already class could be defined for all elements of the array, so it is set with class

  • loop so I know it’s increasing... uses the loop variable itself as ID, but if Voce says n then n uses :D

  • I have tried to test with ID, and it does not capture the user selection, with class yes, because class is used for all elements covered in while, and id would make all elements brought in the modal table have the same id, IE, this is impossible, bring a while with ID instead of class, you know? My problem is to bring only one line and not in capturing the die

1 answer

0

It would suit your case if you insert a line dynamically each time the user finishes filling the modal data?

By clicking on the unidade open the modal with the fields to be completed, after filling the fields using the javascript itself insert a row into the table.

So you allow the user to insert as many rows as you want. And initially your table will only have the header content.

  • when you don’t give a coherent answer to the question just comment @Henrique Oliveira

Browser other questions tagged

You are not signed in. Login or sign up in order to post.