LearnProgramming
LearnProgramming

Reputation: 806

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? by the way, I already deploy yajra datatable

js file

$(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>

Upvotes: 0

Views: 1085

Answers (2)

tompec
tompec

Reputation: 1230

The documentation is really straightforward, if you follow the example it should work. https://datatables.yajrabox.com/eloquent/basic

Upvotes: 1

Benni
Benni

Reputation: 130

  1. Create a model in Laravel
  2. Create a controller for that model, register the routes

I think StackOverflow is not the place to right the application for you. If you have special questions on that, I can help you.

Upvotes: 1

Related Questions