bllim / laravel4数据表 - 不工作

时间:2014-11-04 11:14:57

标签: laravel-4 datatable

我第一次使用Bllim Laravel。

我没有收到任何错误消息,但既没有能够填充数据表中的数据,我得到数据表,但它没有数据。查询工作正常,我可以看到其中的数据,但它没有传递给Datatable或不是数据表能够读取的格式

在此处发布代码:

控制器

public function listAjax() {

    $posts = DB::table('newspaper')->select('id', 'no_of_pages', 'date', 'publishing_time', 'status');
    return Datatables::of($posts, true)->make();}

查看

 <table id="newspaperList" class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>ID</th>
                <th>No of pages</th>
                <th>Date</th>
                <th>Publishing time</th>
                <th>Status</th>

            </tr>
        </thead>
        <tbody>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>

            </tr>

        </tbody>
    </table>
<script type="text/javascript">
$(document).ready(function() {
    $("#newspaperList").dataTable({
        "processing": true,
        "serverSide": true,
        "ajax": "http://localhost:88/epaperlaravel/public/ep-admin/newspaper/listajax",
        "order": [[1, 'desc']],
        "columnDefs": [{//this prevents errors if the data is null
                "targets": "_all",
                "defaultContent": ""
            }],
        "columns": [
            //title will auto-generate th columns
            {"data": "id", "title": "Id", "orderable": true, "searchable": false},
            {"data": "no_of_pages", "title": "Name", "orderable": true, "searchable": true},
            {"data": "date", "title": "Username", "orderable": true, "searchable": true},
            {"data": "publishing_time", "title": "Email", "orderable": true, "searchable": true},
            {"data": "status", "title": "Created", "orderable": true, "searchable": true},
        ]

    });
});

路线

Route::get('ep-admin/newspaper/listajax', array('as' => 'articlesajax', 'uses' => 'NewspaperController@listAjax'));

我哪里出错了?

1 个答案:

答案 0 :(得分:-1)

显示数据需要这么多脚本:

$('#dataTables-example').DataTable( {
        bProcessing: true,
        bServerSide: true,
        dom: "Tfrtip",
        sAjaxSource: "{{ URL::to('/work/showusers') }}",
        
        aaSorting : [[ 0, "desc" ]],
        "aoColumns": [
            { 'sWidth': '60px' },
            { 'sWidth': '130px', 'sClass': 'center' },
            { 'sWidth': '180px', 'sClass': 'center' },
            { 'sWidth': '60px', 'sClass': 'center' },
        ],
        tableTools: {
            sRowSelect: "os",
            aButtons: [
                { sExtends: "editor_create", editor: editor },
                { sExtends: "editor_edit",   editor: editor },
                { sExtends: "editor_remove", editor: editor }
            ]
        },
        language: {
            processing:     "Traitement en cours...",
            search:         "Rechercher&nbsp;:",
            lengthMenu:     "Afficher _MENU_ &eacute;l&eacute;ments",
            info:           "Affichage de l'&eacute;lement _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
            infoEmpty:      "Affichage de l'&eacute;lement 0 &agrave; 0 sur 0 &eacute;l&eacute;ments",
            infoFiltered:   "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
            infoPostFix:    "",
            loadingRecords: "Chargement en cours...",
            zeroRecords:    "Aucun &eacute;l&eacute;ment &agrave; afficher",
            emptyTable:     "Aucune donnée disponible dans le tableau",
            paginate: {
                first:      "Premier",
                previous:   "Pr&eacute;c&eacute;dent",
                next:       "Suivant",
                last:       "Dernier"
            },
            aria: {
                sortAscending:  ": activer pour trier la colonne par ordre croissant",
                sortDescending: ": activer pour trier la colonne par ordre décroissant"
            }
        }
    } );
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-hover" id="dataTables-example">
<thead>
	<tr>
		<th>ID</th>
		<th>Username</th>
		<th>Email</th>
		<th>Password</th>
	</tr>
</thead>
<tfoot>
	<tr>
		<th>ID</th>
		<th>Username</th>
		<th>Email</th>
		<th>Password</th>
	</tr>
</tfoot>
</table>