Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

insight's avatar

Need to list items in datatables . How in Laravel 10 ?

Dear Friends, I am new to Laravel 10 after a gap in Laravel 6 a long time before. I am using datatables for listing data. But I don't know how to do it in Laravel. So please anybody help . I see Yajra datatables, but unfortunately I don't like to use it. Please advise .

Thanks Anes P A

0 likes
2 replies
LaryAI's avatar
Level 58

To use datatables in Laravel, you can follow these steps:

  1. Install DataTables using npm or yarn:
npm install datatables.net --save
  1. Include the DataTables CSS and JS files in your layout file:
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css">
<script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script>
  1. Create a route to fetch the data from the database:
Route::get('/data', function () {
    return Datatables::of(User::query())->make(true);
});
  1. Create a view to display the data:
<table id="users-table">
    <thead>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Created At</th>
            <th>Updated At</th>
        </tr>
    </thead>
</table>

<script>
    $(function() {
        $('#users-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: '/data',
            columns: [
                { data: 'name', name: 'name' },
                { data: 'email', name: 'email' },
                { data: 'created_at', name: 'created_at' },
                { data: 'updated_at', name: 'updated_at' }
            ]
        });
    });
</script>

This example assumes you have a users table in your database with name, email, created_at, and updated_at columns.

Note that this example uses the Yajra DataTables package, but you can use any other DataTables package or library if you prefer.

insight's avatar

Hi Dear Team, In my case I have template and all related js and css. So I plan to do it manually. If any body need more clarification you can ask . I will share here for the needy ...

Thanks Anes P A

Please or to participate in this conversation.