Obtain the id in a datatable that is paged

1

Hello I have a datatable that shows 191 records in 20 pages, it is paged from 10 to 10. I have an edit button in which I click and lift a modal to change a value in the bd, it works well for the first page but not the others. datatable code

<table id="bootstrap-data-table" class="table table-striped table-bordered">
                    <thead>
                      <tr>
                        <th>Nombre</th>
                        <th>Carnet ID</th>
                        <th>Cuenta</th>
                        <th>Salario</th>
                        <th>Operación</th>

                      </tr>
                    </thead>

                    <tbody>
                    <?php

                    $query2 = "SELECT * FROM cuc";
                    $stmt = $db->prepare( $query2 );
                    $stmt->execute();

                    while ($row =$stmt->fetch(PDO::FETCH_ASSOC))
                    {
                        extract($row);

                        ?>
                        <tr>
                            <?php echo "<td>{$row['nombre']}</td>" ?>
                            <?php echo "<td>{$row['num_ci']}</td>" ?>
                            <?php echo "<td>{$row['cuenta']}</td>" ?>
                            <?php echo "<td>{$row['impote']}</td>" ?>
                            <?php echo '<td><span ><button class="btn btn-warning btn-sm modal-button" data-toggle="modal" data-target="#modalRow" data-id="' . $row['id'] . '">' .
                                   '<span class="fa fa-pencil" aria-hidden="true"></span></a></span>' .
                                '</td>';?>



                        </tr>
                        <?php
                    }
                    //

                    ?>

                    </tbody>
                  </table>

Asi tomo el valor del elemento  q seleccione para lebvantar el modal
  <script>
                $(document).ready(function () {
                    $('.modal-button').on('click', function () {
                        var $this = $(this);
                        $('#campo_id').val($this.data('id'));
                    });
                })
            </script>
    
asked by Ylcaceres 14.11.2018 в 16:49
source

1 answer

0

Try this:

$(document).ready(function () {
    $('#bootstrap-data-table').on('click', '.modal-button', function () {
         var $this = $(this);
         $('#campo_id').val($this.data('id'));
    });
})
    
answered by 14.11.2018 в 16:52