首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >bllim/laravel4数据-不工作

bllim/laravel4数据-不工作
EN

Stack Overflow用户
提问于 2014-11-04 11:14:56
回答 1查看 273关注 0票数 1

我第一次使用Bllim Laravel。

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

张贴代码如下:

控制器

代码语言:javascript
复制
public function listAjax() {

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

视图

代码语言:javascript
复制
 <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},
        ]

    });
});

路由

代码语言:javascript
复制
Route::get('ep-admin/newspaper/listajax', array('as' => 'articlesajax', 'uses' => 'NewspaperController@listAjax'));

我哪里出问题了?

EN

回答 1

Stack Overflow用户

发布于 2014-12-13 19:55:25

显示数据需要这样多的脚本:

代码语言:javascript
复制
$('#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"
            }
        }
    } );
代码语言:javascript
复制
<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>

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26733764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档