我在 Infyom Gihthub 上的回答
https://github.com/InfyOmLabs/laravel-generator/issues/972
我是如何做到的(在 yajra/datables-html/builler 中稍作修改 - 参见第 5 步)
0-https://datatables.net/examples/api/multi_filter.html
◦ reference example
1-php artisan infyom.publish:templates
2-resources/infyom/infyom-generator-templates/scaffold/views/datatable_body.stub
datatable_body.stub
@section('third_party_stylesheets')
@include('layouts.datatables_css')
@endsection
{{-- $dataTable->table(['width' => '100%', 'class' => 'table table-striped table-bordered']) --}}
{!! $dataTable->table(['width' => '100%', 'class' => 'table table-striped table-bordered'],true) !!} {{-- drawFooter --}}
3 config/datatables-html.php
'数据表::脚本',
'脚本' => '布局/脚本',
];
4 资源/视图/布局/script.blade.php
$(文档).ready(函数() {
// 设置 - 为每个页脚单元格添加一个文本输入
$("#dataTableBuilder tfoot th").each( function () {
var 标题 = $(this).text();
$(this).html("");
});
});
$(function(){window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}=window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}||{ };window.{{ config('datatables-html.namespace', 'LaravelDataTables') }}["%1$s"]=$("#%1$s").DataTable(%2$s
,initComplete: 函数 () {
// 应用搜索
this.api().columns().every( function () {
var that = this;
$( "input", this.footer() ).on( "keyup change clear", function () {
if ( that.search() !== this.value ) {
那
.search(this.value)
。画();
}
});
});
}
}); }
);
5 • 供应商/yajra/laravel-datatables-html/src/Html/Builder.php
公共函数 generateScripts()
{
$parameters = $this->generateJson();
$parameters=substr($parameters,0,strlen($parameters)-1); # 删除最后一个 } 以添加参数
返回新的 HtmlString(
sprintf($this->template(), $this->getTableAttribute('id'), $parameters)
);
}