Convert Figma logo to code with AI

yajra logolaravel-datatables

jQuery DataTables API for Laravel

4,744
862
4,744
51

Top Related Projects

Tables plug-in for jQuery

Free Bootstrap Admin & Dashboard Template

43,907

AdminLTE - Free admin dashboard template based on Bootstrap 5

Next Generation Vue UI Component Library

12,496

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

2,918

Responsive Bootstrap 3 Admin Template based on AdminLTE with vue.js

Quick Overview

Yajra/laravel-datatables is a Laravel package that provides server-side processing for DataTables, a popular jQuery plugin for creating interactive tables. It simplifies the integration of DataTables with Laravel applications, offering a seamless way to handle large datasets efficiently.

Pros

  • Easy integration with Laravel applications
  • Supports server-side processing for improved performance with large datasets
  • Offers a fluent API for customizing DataTables output
  • Provides built-in support for various data sources (Eloquent, Query Builder, Collection)

Cons

  • Requires knowledge of both Laravel and DataTables
  • May have a learning curve for developers new to server-side processing
  • Limited customization options for complex table structures
  • Dependency on jQuery (if using the default DataTables frontend)

Code Examples

  1. Basic usage with Eloquent:
use DataTables;

public function getUsers()
{
    return DataTables::of(User::query())->toJson();
}
  1. Adding custom columns:
return DataTables::of(User::query())
    ->addColumn('action', function ($user) {
        return '<a href="/users/'.$user->id.'/edit">Edit</a>';
    })
    ->rawColumns(['action'])
    ->toJson();
  1. Applying filters:
return DataTables::of(User::query())
    ->filter(function ($query) {
        if (request()->has('name')) {
            $query->where('name', 'like', '%'.request('name').'%');
        }
    })
    ->toJson();

Getting Started

  1. Install the package via Composer:

    composer require yajra/laravel-datatables-oracle
    
  2. Add the service provider to your config/app.php (Laravel 5.4 and below):

    Yajra\DataTables\DataTablesServiceProvider::class,
    
  3. Publish the configuration file:

    php artisan vendor:publish --provider="Yajra\DataTables\DataTablesServiceProvider"
    
  4. In your controller, use the DataTables facade:

    use DataTables;
    
    public function getUsers()
    {
        return DataTables::of(User::query())->toJson();
    }
    
  5. In your view, initialize DataTables:

    <table id="users-table">
        <thead>
            <tr>
                <th>ID</th>
                <th>Name</th>
                <th>Email</th>
            </tr>
        </thead>
    </table>
    
    <script>
    $(function() {
        $('#users-table').DataTable({
            processing: true,
            serverSide: true,
            ajax: '{{ route("get.users") }}'
        });
    });
    </script>
    

Competitor Comparisons

Tables plug-in for jQuery

Pros of DataTables

  • More versatile and can be used with various frameworks and libraries
  • Extensive documentation and community support
  • Offers more advanced features out-of-the-box

Cons of DataTables

  • Steeper learning curve for complex implementations
  • May require more manual configuration for Laravel integration

Code Comparison

DataTables:

$(document).ready(function() {
    $('#example').DataTable({
        ajax: '/api/data',
        columns: [
            { data: 'name' },
            { data: 'position' },
            { data: 'office' }
        ]
    });
});

laravel-datatables:

use DataTables;

public function getIndex()
{
    return DataTables::of(User::query())->make(true);
}

Key Differences

  • laravel-datatables is specifically designed for Laravel, offering seamless integration
  • DataTables provides more flexibility for use across different platforms
  • laravel-datatables simplifies server-side processing in Laravel applications
  • DataTables offers more customization options but may require more setup time

Use Cases

  • Choose laravel-datatables for Laravel-specific projects with simpler requirements
  • Opt for DataTables when working on cross-platform projects or need advanced features

Both libraries are powerful tools for creating interactive tables, with the choice depending on your specific project needs and environment.

Free Bootstrap Admin & Dashboard Template

Pros of CoreUI Free Bootstrap Admin Template

  • Provides a complete admin dashboard UI with pre-built components and layouts
  • Offers a responsive design that works well on various devices and screen sizes
  • Includes multiple color schemes and customization options out of the box

Cons of CoreUI Free Bootstrap Admin Template

  • Limited to frontend UI components, lacking backend integration capabilities
  • May require more manual customization for specific data handling needs
  • Not specifically optimized for Laravel integration

Code Comparison

CoreUI (HTML/CSS):

<div class="card">
  <div class="card-header">Featured</div>
  <div class="card-body">
    <h5 class="card-title">Special title treatment</h5>
    <p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

Laravel Datatables (PHP):

$users = DB::table('users')->select(['id', 'name', 'email', 'created_at', 'updated_at']);

return Datatables::of($users)
    ->addColumn('action', function ($user) {
        return '<a href="#edit-'.$user->id.'" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
    })
    ->make(true);

The code snippets highlight the different focus areas of each project, with CoreUI emphasizing UI components and Laravel Datatables focusing on server-side data processing and presentation.

43,907

AdminLTE - Free admin dashboard template based on Bootstrap 5

Pros of AdminLTE

  • Comprehensive admin dashboard template with a wide range of UI components
  • Responsive design out-of-the-box, suitable for various screen sizes
  • Regular updates and active community support

Cons of AdminLTE

  • Not specifically designed for Laravel, may require additional integration work
  • Steeper learning curve for developers unfamiliar with the template structure

Code Comparison

AdminLTE (HTML/CSS):

<div class="card">
  <div class="card-header">
    <h3 class="card-title">DataTable with default features</h3>
  </div>
  <div class="card-body">
    <table id="example1" class="table table-bordered table-striped">
      <!-- Table content -->
    </table>
  </div>
</div>

Laravel-datatables (PHP):

use DataTables;

public function getUsers()
{
    return DataTables::of(User::query())->make(true);
}

While AdminLTE provides a complete admin template with various UI components, Laravel-datatables focuses specifically on integrating DataTables with Laravel. AdminLTE offers more visual customization options but requires more setup for Laravel projects. Laravel-datatables, on the other hand, seamlessly integrates with Laravel and provides server-side processing out-of-the-box, making it more efficient for handling large datasets in Laravel applications.

Next Generation Vue UI Component Library

Pros of PrimeVue

  • Comprehensive UI component library for Vue.js applications
  • Offers a wide range of customizable components beyond just data tables
  • Active development and frequent updates

Cons of PrimeVue

  • Steeper learning curve due to its extensive feature set
  • May introduce unnecessary overhead if only data table functionality is needed
  • Requires Vue.js, which may not be suitable for Laravel-specific projects

Code Comparison

Laravel DataTables:

use DataTables;

return DataTables::of(User::query())->make(true);

PrimeVue:

<template>
  <DataTable :value="users">
    <Column field="name" header="Name"></Column>
    <Column field="email" header="Email"></Column>
  </DataTable>
</template>

<script>
export default {
  data() {
    return {
      users: []
    }
  }
}
</script>

Summary

Laravel DataTables is specifically designed for Laravel applications, offering seamless integration with Laravel's backend. It's ideal for projects that primarily need server-side processing of data tables.

PrimeVue, on the other hand, is a more comprehensive UI library for Vue.js applications. It provides a wide range of components beyond just data tables, making it suitable for building entire front-end interfaces. However, it may be overkill for Laravel projects that only require data table functionality.

The choice between the two depends on the project's specific requirements, the preferred frontend framework, and the need for additional UI components beyond data tables.

12,496

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

Pros of ag-grid

  • More feature-rich with advanced functionalities like pivoting, grouping, and aggregation
  • Supports multiple frameworks (React, Angular, Vue) and vanilla JavaScript
  • Highly customizable with extensive API and theming options

Cons of ag-grid

  • Steeper learning curve due to its complexity and extensive features
  • Requires more setup and configuration compared to laravel-datatables
  • Commercial license needed for some advanced features

Code Comparison

laravel-datatables:

return DataTables::of($users)
    ->addColumn('action', function ($user) {
        return '<a href="#" class="btn btn-xs btn-primary">Edit</a>';
    })
    ->make(true);

ag-grid:

const gridOptions = {
    columnDefs: [
        { field: 'name' },
        { field: 'age' },
        { field: 'action', cellRenderer: params => '<button>Edit</button>' }
    ],
    rowData: users
};
new agGrid.Grid(gridDiv, gridOptions);

Key Differences

  • laravel-datatables is specifically designed for Laravel, while ag-grid is framework-agnostic
  • ag-grid offers more advanced features but requires more setup
  • laravel-datatables integrates seamlessly with Laravel's backend, while ag-grid is primarily client-side
  • ag-grid provides more flexibility in terms of customization and advanced functionalities
2,918

Responsive Bootstrap 3 Admin Template based on AdminLTE with vue.js

Pros of CoPilot

  • Provides a complete admin template with a modern UI design
  • Includes built-in components for charts, tables, and forms
  • Offers a responsive layout for various screen sizes

Cons of CoPilot

  • Less focused on data handling compared to Laravel Datatables
  • May require more customization for specific data-intensive applications
  • Limited to Vue.js framework, while Laravel Datatables is more flexible

Code Comparison

Laravel Datatables:

$users = DB::table('users')->select(['id', 'name', 'email']);
return Datatables::of($users)->make(true);

CoPilot:

<template>
  <v-data-table :headers="headers" :items="desserts" class="elevation-1"></v-data-table>
</template>

Summary

Laravel Datatables is a specialized package for handling server-side processing of DataTables in Laravel applications. It excels in managing large datasets efficiently.

CoPilot, on the other hand, is a more comprehensive admin template built with Vue.js. It provides a full-featured dashboard with various UI components, including tables, but is not specifically focused on advanced data handling like Laravel Datatables.

The choice between these two depends on the project requirements. For data-intensive applications requiring server-side processing, Laravel Datatables might be more suitable. For projects needing a complete admin interface with various components, CoPilot could be a better fit.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

jQuery DataTables API for Laravel

Join the chat at https://gitter.im/yajra/laravel-datatables Donate Donate

Laravel 4.2|5.x|6|7|8|9|10|11 Latest Stable Version Continuous Integration Static Analysis

Total Downloads License

Laravel package for handling server-side works of DataTables jQuery Plugin via AJAX option by using Eloquent ORM, Fluent Query Builder or Collection.

use Yajra\DataTables\Facades\DataTables;

return DataTables::eloquent(User::query())->toJson();
return DataTables::query(DB::table('users'))->toJson();
return DataTables::collection(User::all())->toJson();

return DataTables::make(User::query())->toJson();
return DataTables::make(DB::table('users'))->toJson();
return DataTables::make(User::all())->toJson();

Sponsors

DataTables JetBrains.com Blackfire.io

Requirements

Documentations

Laravel Version Compatibility

LaravelPackage
4.2.x3.x
5.0.x6.x
5.1.x6.x
5.2.x6.x
5.3.x6.x
5.4.x7.x, 8.x
5.5.x8.x
5.6.x8.x
5.7.x8.x
5.8.x9.x
6.x9.x
7.x9.x
8.x9.x
9.x10.x
10.x10.x
11.x11.x

Quick Installation

composer require yajra/laravel-datatables-oracle:"^11"

Service Provider & Facade (Optional on Laravel 5.5+)

Register provider and facade on your config/app.php file.

'providers' => [
    ...,
    Yajra\DataTables\DataTablesServiceProvider::class,
]

'aliases' => [
    ...,
    'DataTables' => Yajra\DataTables\Facades\DataTables::class,
]

Configuration (Optional)

php artisan vendor:publish --provider="Yajra\DataTables\DataTablesServiceProvider"

And that's it! Start building out some awesome DataTables!

Debugging Mode

To enable debugging mode, just set APP_DEBUG=true and the package will include the queries and inputs used when processing the table.

IMPORTANT: Please make sure that APP_DEBUG is set to false when your app is on production.

PHP ARTISAN SERVE BUG

Please avoid using php artisan serve when developing with the package. There are known bugs when using this where Laravel randomly returns a redirect and 401 (Unauthorized) if the route requires authentication and a 404 NotFoundHttpException on valid routes.

It is advised to use Homestead or Valet when working with the package.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email aqangeles@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.