<table class="table table table-striped table-bordered table-sm row-border hover" id="datatableexample">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Parent</th>
<th scope="col">Category</th>
<th scope="col">Description</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of data">
<th scope="row">{{item.id}}</th>
<td>{{item.parend_id}}</td>
<td>{{item.category_name}}</td>
<td>{{item.description}}</td>
</tr>
</tbody>
</table>
组件代码
this.auth.categorylist().subscribe((data:any)=>{
console.log(data);
this.data=data;
setTimeout(()=>{
$('#datatableexample').DataTable( {
pagingType: 'full_numbers',
// serverSide: true,
pageLength: 10,
processing: true,
//ajax: data,
// ajax: {
// "url": "data.json",
// "type": "POST"
// },
lengthMenu : [5, 10, 25]
} );
}, 1);
},
(err)=>{
this.message = err.error.message;
//this.recordStatus = false;
console.log(err);
})
api服务代码
// category list
categorylistserver(){
const user: any = localStorage.getItem('user');
const userObj = JSON.parse(user);
const token = userObj.token;
const headers = new HttpHeaders({
Authorization: `Bearer ${token}`,
});
return this.http.get(environment.API_URL+'category-index2',{
headers: headers,
});
}
拉威尔控制器代码
public function serversitepaging(Request $request){
/**
* @var user $user
*/
$catList= DB::table('categories')->get();
// Verify
if($catList->isEmpty()){
return response(['message' => 'Record not found'], 400);
} else {
return response($catList,200);
}
}
请帮忙
如何使用laravel和ajax方法添加angular 12数据表
我想用服务器端分页和排序过滤器显示我的分类数据,因为数据库中有1000个数据。
以上代码运行良好,但当我们启用服务器端选项时,数据不会显示