dongyoucha0645 2017-04-25 04:43
浏览 106

使用ajax jquery填充数据时,分页和搜索框不会显示在bootstrap数据表中

When i display data in bootstrap datatable using ajax jquery then pagination and search box is not display.so how to solve this problem

My html sample code is here.

 <div class="row" style="margin-top: 2em;">
     <div class="panel panel-white">
       <div class="panel-heading clearfix">

       </div>
       <div class="panel-body">
           <div id="live_data" >
             //data table display here                         
           </div>
       </div>
    </div>

And my ajax file code is here

    <?php

    $output='';     
    $output.='  <div class="table-responsive">
                   <table id="example" class="table table-striped table-
                     bordered" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </thead>
    <tfoot>
        <tr>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th>Salary</th>
        </tr>
    </tfoot>
    <tbody>
        <tr>
            <td>Tiger Nixon</td>
            <td>System Architect</td>
            <td>Edinburgh</td>
            <td>61</td>
            <td>2011/04/25</td>
            <td>$320,800</td>
        </tr>
        <tr>
            <td>Garrett Winters</td>
            <td>Accountant</td>
            <td>Tokyo</td>
            <td>63</td>
            <td>2011/07/25</td>
            <td>$170,750</td>
        </tr>
        <tr>
            <td>Ashton Cox</td>
            <td>Junior Technical Author</td>
            <td>San Francisco</td>
            <td>66</td>
            <td>2009/01/12</td>
            <td>$86,000</td>
        </tr>                                                        
    </tbody>
</table>
</div>';
echo $output;
?>

And my jquery function is here

 getcamera();
        function getcamera(){
            $.ajax({
                type:"POST",
                url:'../ajaxfiles/ajax_getcamera.php',
                success:function(data){
                    $('#live_data').html(data);

                }
            });
        }


This above code is work properly but search box and pagination is not display

so how to solve that problem???

  • 写回答

1条回答 默认 最新

  • drpiqlzrh62917192 2017-04-25 04:48
    关注
     `getcamera();
        function getcamera(){
            $.ajax({
                type:"POST",
                url:'../ajaxfiles/ajax_getcamera.php',
                success:function(data){
                    $('#live_data').html(data);
                     $('#example').DataTable();// Add this line.
                }
            });
        }`
    

    Above code will work. This is not the best solution. For good ajax implementation you can see example usages at https://datatables.net/examples/ajax/simple.html And https://datatables.net/examples/server_side/simple.html

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器