DataTables通过Mysql的ajax实现



我想在不重新编码页面的情况下显示表的内容,并且该部分正在工作,但当我这样做时,我丢失了数据表中的所有选项,如:搜索、切换、滚动。我该怎么修?

Jquery:

$(document).ready(function() {
 var table = $('#Tab_uzytkownicy').DataTable( {
    "scrollX": true,
 "language": {
            "url": "Polski.txt"
        }
    } );
    $('a.toggle-vis').on( 'click', function (e) {
        e.preventDefault();
        var column = table.column( $(this).attr('data-column') );
        column.visible( ! column.visible() );
    } );

(function pull() {
    $.ajax({
        url: 'User_dane.php',
        type: "GET",
   success: function(out) {
   $("#user_tabele").html(out);
},
        dataType: "html",
        complete: setTimeout(function() {pull()}, 1000),
        timeout: 1000
    })
})();   
} );

HTML:

 <div class="container-fluid" draggable="true">
                      <br>
            <div class="col-xs-12">
                        <div>
        Ukryj:
        <a class="toggle-vis" data-column="1">Login</a> - 
        <a class="toggle-vis" data-column="2">E-mail</a> - 
        <a class="toggle-vis" data-column="3">Imie</a> - 
        <a class="toggle-vis" data-column="4">Nazwisko</a> - 
        <a class="toggle-vis" data-column="5">Telefon</a> - 
        <a class="toggle-vis" data-column="6">Aktywne</a>-
        <a class="toggle-vis" data-column="7">Uprawnienia</a>-
        <a class="toggle-vis" data-column="8">Data Rejestracji</a>
    </div>
    </div>
    <div class="col-xs-12">
    <table id="Tab_uzytkownicy" class="display" cellspacing="0" width="100%">
        <thead>
                  <br>
            <tr >
<th >ID</th>
<th>Login</th>
<th>E-mail</th>
<th>Imie</th>
<th>Nazwisko</th>
<th>Telefon</th>
<th>Aktywne</th>
<th>Uprawnienia</th>
<th>Data Rejestracji</th>
<th>Usuń</th>
<th>Edytuj</th>
                </tr>
            </thead>

    <tbody id ="user_tabele">

    </tbody>
</table> </div>
            </div>
  </div>

PHP:

<?php
include 'Panel_Logowanie/config.php';
db_connect();
        $query = mysql_query("select * from users");
        $i=0;
        while($fetch = mysql_fetch_array($query)):

        echo '<tr>';
        echo'<td> '.$fetch['user_id'].'</td>';
        echo'<td> '.$fetch['user_name'].'</td>';
        echo'<td> '.$fetch['user_email'].'</td>';
        echo'<td> '.$fetch['user_imie'].'</td>';
        echo'<td> '.$fetch['user_nazwisko'].'</td>';
        echo'<td> '.$fetch['user_telefon'].'</td>';
        echo'<td> '.$fetch['user_konto_akty'].'</td>';
        echo'<td> '.$fetch['user_uprawnienia'].'</td>';
        echo'<td>' .date("d.m.Y, H:i", $fetch['user_regdate']). '</td>';
        echo'<td>  <a class="btn btn-primary btn-sm" href="Kasuj_tab.php?user_id='.$fetch['user_id'].'">Usuń</a></td>';
        ?>
                <td>
                    <a class="btn btn-small btn-primary" data-toggle="modal" data-target="#exampleModal_user" data-whatever1="<?php echo $fetch['user_id']; ?>">Edit</a></td>
<?php
            echo '</tr>';
        endwhile;
?>
$("#user_tabele").html(out);

相反,您可以使用附加功能

$("#user_tabele").append(out);

最新更新