【问题标题】:Show data in datatable from the database在数据库的数据表中显示数据
【发布时间】:2019-04-08 20:49:41
【问题描述】:

我想在数据表中显示数据,但显示全部为空 价值观

控制器:

 public function ex(Request $request){
            $table =  \DB::table('company')->select('name','type','address','city','email','description')->get();
            return $table;
        }

display.blade.php

<body>
<button id="mybutton">Click Me</button><br><br><br>
<table border="1px" id="imp" class="table table-striped table-bordered" style="width:100%">
    <thead>
    <tr>
        <th>Name</th>
        <th>Type</th>
        <th>Address</th>
        <th>City</th>
        <th>Email</th>
        <th>Description</th>
    </tr>
    </thead>
    <tbody>

    </tbody>
</table>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
    $(document).ready(function () {
        $("#mybutton").click(function(){
            $('#imp').DataTable({
                "processing": true,
                "serverSide":true,
                "ajax": {"url":"display"},
                "columns": [
                    { "data": "name" },
                    { "data": "type"},
                    { "data": "address" },
                    { "data": "city" },
                    { "data": "email" },
                    { "data": "description" }
                ]
            });
        });
        });

</script>
</body>

我想在数据表中以表格形式显示数据 页 在做 dd();数据以 JSON 格式出现,但显示在 html 上 页面

【问题讨论】:

    标签: jquery ajax datatables laravel-5.4


    【解决方案1】:
    You missed the dataSrc to pass after the ajax URL.
    
    <script>
            $(document).ready(function () {
                $("#mybutton").click(function(){
                    $('#imp').DataTable({
                        "processing": true,
                        "serverSide":true,
                        "ajax": {"url":"display", dataSrc:''},
                        "columns": [
                            { "data": "name" },
                            { "data": "type"},
                            { "data": "address" },
                            { "data": "city" },
                            { "data": "email" },
                            { "data": "description" }
                        ]
                    });
                });
            });
    
        </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 2018-12-30
      • 2014-11-29
      相关资源
      最近更新 更多