Download the PHP package mzprog/datatables without Composer

On this page you can find all versions of the php package mzprog/datatables. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package datatables

datatables

create a better tables with few lines of code.

Installation

simply install the package by:

composer require mzprog/datatables

make sure that livewire is installed, and styles and scripts added to the blade layout: @livewireStyles and @livewireScripts

Basic Usage

Column class

just add Column::name('id') to your columns array, and it will be added and viewed in your table, but it will be labeled as Id.

To change the label name just use the second parameter Column::name('id', 'ID').

The name will be used as the array index, and database field by defualt.

field method is used to allow you to different key for the column as in this example(orderable& edit will be explained later):

Column::name('added')->field('created_at')
    ->orderable()
    ->edit(fn($row) => $row->created_at->diffForHumans()),

we have change the format for created_at but can't store it in same properties (because casted to date, and work as getCreateAtAttribute).

so when use orderable it will order using created_at.

edit method is used to change or add data.
it accept callback with the current raw data as parameter, example:

Column::name('full_name', 'Name)
    ->edit(fn($raw) => "{$raw->first_name} {$raw->last_name}")

orderablemethod will allow you to order the column by pressing on the column name. it will order your data based on your field name, unless you add a callback as a parameter. the callback parameter are: the query Builder, and the order direction, example:

return [
    Column::name('id', 'ID')->orderable(),
    Column::name('full_name', 'Name)
        ->orderable(fn($q, $dir) => $q->orderBy('first_name', $dir)->orderBy('last_name', $dir))
        ->edit(fn($raw) => "{$raw->first_name} {$raw->last_name}"),
];

searchable method is work as orderable, and the callback function will pass the search keyword instead of order direction, example:

Column::name('full_name', 'Name)
    ->searchable(
        fn($q, $keyword) => $q
            ->where(DB::raw('CONCAT(first_name," ", last_name)'), 'like', "%${keyword}%")
    )
    ->orderable(fn($q, $dir) => $q->orderBy('first_name', $dir)->orderBy('last_name', $dir))
    ->edit(fn($raw) => "{$raw->first_name} {$raw->last_name}"),

raw method is used when you need to print HTML in your table. example:

Column::name('actions')->raw()
    ->edit(fn($row) => '<a href="' . route('users.show',['user' => $row->id]) . '" >View</a>';

Filter Class

If you want to select one or more value as a filter, like you only need to see rows from today, you can use:

public function filters()
{
    return [
        Filter::name('date', 'Select a Date'),
    ];
}

this will let you filter from your table using date column, also you can skip the label name, by defualt it will be Date.

also you can use custom data and filters:

example 1 (if you want to filter by name first letter):

Filter::name('name')->options(function () {
    $options = User::query()
        ->select([
            DB::raw('LEFT(name,1) as letter'),
            DB::raw('COUNT(*) as total')
        ])->groupBy('letter')->get();

    return $options->map(fn ($d) => [
        'value' => $d['letter'],
        'name' => "Starts with '{$d['letter']}'",
        'total' => $d['total'],
    ])->toArray();
})
->filter(function (Builder $query, array $values) {
    $query->whereIn(DB::raw('LEFT(name,1)'), $values);
})

for options you need to return array of options, and option has (name, value, total).

filter if this filter is selected you can add conditions to the provided query, and you will get also array of the selected values.

example 2(filter by success: success, fail)

Filter::name('success')->options(function () {
    return [
        [
            'name' => 'Success',
            'value' => '>=',
            'total' => Exam::where('points', ">=", 50)->count()
        ],
        [
            'name' => 'Fail',
            'value' => '<',
            'total' => Exam::where('points', "<", 50)->count()
        ],
    ];
})
->filter(function (Builder $query, array $values) {
    if(count($values) ==2) return;
    $val = current($values);
    $query->whereIn('points', $val, 50);
})

All versions of datatables with dependencies

PHP Build Version
Package Version
Requires livewire/livewire Version ^2.10
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mzprog/datatables contains the following files

Loading the files please wait ....