简体   繁体   English

如何使用Ajax Crud在Laravel 5.4中实现数据表

[英]How to implement datatable into laravel 5.4 with ajax crud

my website contain basic CRUD operation with ajax build in, my question is, how to implement datatable? 我的网站包含内置ajax的基本CRUD操作,我的问题是,如何实现数据表? by the way, I already deploy yajra datatable 顺便说一句,我已经部署了yajra数据表

js file js文件

$(function () {

    $('#example').DataTable({

});});

function manageRow(data) {
var rows = '';
$.each( data, function( key, value ) {
    rows = rows + '<tr>';
    rows = rows + '<td>'+value.title+'</td>';
    rows = rows + '<td>'+value.description+'</td>';
    rows = rows + '<td data-id="'+value.id+'">';
    rows = rows + '<button data-toggle="modal" data-target="#edit-item" class="btn btn-primary edit-item">Edit</button> ';
    rows = rows + '<button class="btn btn-danger remove-item">Delete</button>';
    rows = rows + '</td>';
    rows = rows + '</tr>';
});
$("tbody").html(rows);}

view 视图

<table id="example" class="display" cellspacing="1" width="100%">
<thead>
   <tr>
     <th>Name</th>
     <th>Position</th>
     <th>Office</th>
 </tr>
</thead>

<tbody>

</tbody></table>
  1. Create a model in Laravel 在Laravel中创建模型
  2. Create a controller for that model, register the routes 为该模型创建一个控制器,注册路由

I think StackOverflow is not the place to right the application for you. 我认为StackOverflow并不是适合您的应用程序的地方。 If you have special questions on that, I can help you. 如果您对此有特殊疑问,我可以为您提供帮助。

The documentation is really straightforward, if you follow the example it should work. 该文档非常简单明了,如果您按照示例操作,它将起作用。 https://datatables.yajrabox.com/eloquent/basic https://datatables.yajrabox.com/eloquent/basic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM