php - Laravel Yajra 上的分页 分页不起作用
问题描述
我正在开发一个使用 API 的项目,它包含大量数据,所以我需要一个数据表来管理所有数据。不幸的是,当我应用数据表时,分页不起作用,当我单击分页时,页面加载并显示第一页内容。有什么解决方案。
这是我的控制器代码
public function json()
{
$token = session()->get('accessToken');
$ch = curl_init('http://api-link');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-access-token:' . $token . ''));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data_response = json_decode($response)->data;
return Datatables::of($data_response)->make(true);
}
这是我的刀片代码
@section('content')
<div id="page-content" class="page-content">
<div id="page-content-scroll"><!--Enables this element to be scrolled -->
<div class="content">
@component('layouts.topnav-admin')@endcomponent
<a href="/tag/create" class="button button-red button-full button-rounded button-s uppercase ultrabold button-add">Tambah</a>
<table class="table-borders-dark table-list" id="table_tag">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
@endsection
@section('script')
<script>
$(document).ready(function () {
$('#table_tag').DataTable({
processing: true,
serverSide: true,
order: [[ 0, "desc" ]],
ajax: {
url: "tag/json",
type: "GET",
},
columns: [
{data: 'id', name: 'id', render:function(data, type, row){
return "<a href='/tag/edit/"+ row.id +"'>" + row.id + "</a>"},
},
{data: 'name', name: 'name', render:function(data, type, row){
return "<a href='/tag/edit/"+ row.id +"'>" + row.name + "</a>"},
},
]
});
});
</script>
@endsection
这是用于响应数据
// 20191206112726
// http://localhost:8000/tag/json
{
"draw": 0,
"recordsTotal": 40,
"recordsFiltered": 40,
"data": [
{
"id": "16",
"name": "abc"
},
{
"id": "19",
"name": "xyz"
},
{
"id": "30",
"name": "athletic"
}
],
"input": [
]
}
谢谢
解决方案
推荐阅读
- node.js - 带有 NodeJS 的用户名/密码的 TLS
- javascript - TypeError: firebase.initializeApp 不是仅当 jest 运行测试时的函数
- ios - UIPageViewController 在 viewDidLoad() 之后加载 ViewController 的延迟
- java - 二进制文件的十六进制表示
- python - AWS EC2 连续一个月运行 python 程序
- typescript - 从 Webstorm 中的 docker 容器远程调试 koa 应用程序(Typescript)
- ios - Flutter 在执行 Flutter build ios 后卡在 Building Dart 代码上
- html - 如何仅使用 html 或 css 为音频制作切换按钮?
- shopify - 如何删除单词之间的空格 Liquid-C (Shopify)
- javascript - 为什么单击锚链接后我的 jscript 开始出错