【问题标题】:Trouble with Chumper's DataTables plugin for laravel用于 laravel 的 Chumper 的 DataTables 插件有问题
【发布时间】:2015-04-16 06:56:07
【问题描述】:

我正在尝试使用 Chumper 数据表库在页面上显示表格。

我有我的发票模型

类发票扩展了 Eloquent { 受保护的 $table = '发票';

在我看来:

{{ Datatable::table()
->addColumn('id','client_id')       // these are the column headings to be shown
->setUrl(route('api.invoices'))   // this is the route where data will be retrieved
->render() }}

控制器

public function getDatatable()
{
    return Datatable::collection(Invoice::all(array('id','client_id')))
        ->showColumns('id', 'client_id')
        ->searchColumns('client_id')
        ->orderColumns('id','client_id')
        ->make();
}

路线

Route::get('api/invoices', array('as'=>'api.invoices', 'uses'=>'InvoiceController@getDatatable'));

表头已显示,但下方没有数据。有什么想法吗?

在 Chrome 中这行代码也出现错误

 oTable = jQuery('#CIZatgPm').dataTable({
Uncaught Type error: undefined is not a function

【问题讨论】:

  • 那个 javascript 错误是说 dataTable 函数没有被定义。您是否在 HTML 中包含了 datatables javascript 库?

标签: javascript laravel datatable


【解决方案1】:

此错误表明您在运行 Datatable::table() 之前没有加载 jQuery 和/或数据表。

解决此问题的方法是将 jQuery 和 Datatables 添加到您的页面(或者更改 Datatables javascript 模板以延迟加载数据表,直到加载 jQuery 和 Datatables)。

将以下内容添加到您的<head>(确保您也有 jQuery!):

 <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.9.4/css/jquery.dataTables.css">
 <script src="//cdn.datatables.net/1.9.4/js/jquery.dataTables.min.js"></script>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-22
    • 1970-01-01
    • 2015-07-21
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多