Download the PHP package gustocoder/laravel-datatable without Composer
On this page you can find all versions of the php package gustocoder/laravel-datatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gustocoder/laravel-datatable
More information about gustocoder/laravel-datatable
Files in gustocoder/laravel-datatable
Package laravel-datatable
Short Description Laravel datatable package that provides sorting, allows you to optionally add an extra column, under which you can add buttons for CRUD operations. The button creation method will automatically generate links and send the individual record id to the route name you pass to it. You can configure whether you want the records to be clickable, sortable or not. There is also pagination. Built using Laravel 11.0 but will work on most recent versions. It uses Bootstrap 5 to wrap your responsive table in a nice customizable panel
License MIT
Informations about the package laravel-datatable
Laravel datatable package
Instantly generate beautiful tables from your Laravel models
How to use it
Install it
After installation The configuration file will be created for you in:
'config/laravel-datatable.php'
The stylesheets should be created for you in:
'public/vendor/datatable.css'
If you have issues, make sure that the LaravelDatatableServiceProvider class is registered in your /bootstrap/providers.php
The main class here is DatatableController
Use it
You would display the generated table ('usersTable') in your view blade file like so:
Description of the arguments passed to DatatableController
-
The first argument here (required) must be the exact spelling of the model to use.
-
The second argument (optional) is the route path you have defined in your route file for the view file where the fetched data from the model will be displayed. It is optional because you may choose to have the records not clickable and, or, not sortable-in which case there will be no anchor links generated or fetch more data.
-
The third argument (optional) is an associative array of specific fields you want to fetch if you do not want to fetch all fields on the model. The keys are the actual DB table field names, while the values which are optional, are strings you want to appear on the generated table as aliases in place of the table field name.
-
The fourth argument (optional) is an array of configuration that you want to override the the base config settings for the current table you are creating. You pass in an associative array of config settings and their values. For example:
-
By default, the system assumes that your table has a 'date' field, that is a datetime/timestamp field and its data will be converted for you from the 'Y-m-d' format to the 'd-m-Y' format.
-
If your table's datetime/timestamp field, is named something other than 'date', and you want this date format conversion, you need to pass a config array to the 4th argument here in order to tell the system the name of your date field. For example, if the name of your date field is 'created_at', pass it like so:
-
If you do not want this conversion, remove the 'date_field' setting entirely from your config file.
-
By default, the system also orders the date by a 'date' field. If you want ordering to be done using a different field, or if your date field is named something else; pass the config entry here in the 4th argument to specify the field to be ordered on by default like so:
-
Optionally, you can set the heading for your table in this same config 4th argument like so:
Otherwise, the system is going to generate this heading for you using the model name you passed in like in the format: 'Modelname data'.
-
A word on the date_field config setting for the orderBy clause
-You must only use a datetime/timestamp type for this field, and not a 'date' format
because the package code expects a time segment in the date string given.
How to handle actions on the action (manage) buttons
-When you indicate that you want the table records to be clickable (config file), the system
will create anchor links for the individual records and automatically send the record ids
with these links. All you then have to do create the routes to match those paths.
-Also, when you add buttons, the system will add anchor links to them, adding in the record
ids as well. Here is an example of how you would create a route to handle deletion of a
record:
-
routes\web.php
-
Controller
- The delete button that the getTable() method of DatatableController will create will have an anchor link pointing to '/deleteUser/6' where 6 is the record id against that specific delete button. The defined deleteUser route above will take the request to the deleteUser() method of the calling class (ExampleController).
Customising the look of your table
It is up to you to style the generated table as you wish.
The table is wrapped in a panel with the id of: 'datatablePanel' or any id you
specified for it when you called getTable($panelId)
The table element itself also has an id generated from the model name like so
id='modelname_table'
You may use the panelId and table id attributes to customise the styling of the
table.
-
So, remember to reference datatable stylesheet from the path where it lives (in 'vendor/laravel-datatable/css/datatable.css') into your layout file like so:
-
Remember that to style the table, you need to edit the CSS file in 'public/vendor/laravel-datatable/css/datatable.css'
The CSS selectors currently point to the default panelId value which is 'datatablePanel'. If you passed in a panelId to 'getTable()' when you called it; you need to go into the CSS file ('public/vendor/laravel-datatable/css/datatable.css') and change the CSS selector references from 'datatablePanel' to the value of the panelid you passed in to getTable().
-
Once more, if you cannot find the following files in your project after installing the package:
- /config/laravel-datatable.php
- /vendor/laravel-datatable/css/datatable.css
Then you need to run this command to fix that:
Finally, make sure that the LaravelDatatableServiceProvider class is registered in your /bootstrap/providers.php file like so: