Laravel DataGrid Guide

Looking for a robust DataGrid solution for your Laravel application? Our product offers a comprehensive DataGrid interface with CRUD (Create, Read, Update, Delete) features, providing a seamless way to manage and display data without relying on Eloquent.

Following is the guide to integrate PHP Editable DataGrid with Laravel v11.

Step1: Folder placements in Laravel.

There are 2 main folders in Grid 4 PHP Framework package archive. You need to:

Copy the contents of lib/inc folder —> <Laravel>/app/Classes/Gridphp
Copy the contents of lib/js folder —> <Laravel>/public/assets/gridphp

The ‘app/Classes’ folder does not exist by default in Laravel. You may create it for 3rd party class libraries.
Create another folder inside it with name ‘Gridphp’ and move all contents of ‘lib/inc’ in it. Final result will look like this:

In similar way, copy the files from lib/js to laravel/public/assets/gridphp. Final result should look like following:

Step2: Setting Up Factory Class & Controller:

To use datagrid object in controller, we have setup a factory class in ‘laravel/app/Gridphp.php’. The purpose of this class is to:

  • Set the database configuration.
  • Autoload the library files
  • Provide a get() method to be used in controller.

Now in controller, we used the namespace of our factory class and called the get() function to get the datagrid object. The rest code is same as in our demos. Finally, we passed the output of render() function to view with a variable name ‘grid’.

For demo purpose, we’ve modified ‘laravel/app/Http/Controllers/WelcomeController.php’

Step2: Setting View code:

  1. In view code, we included the JS/CSS files from the ‘js’ folder which we copied in Step 1.1
  2. And using blade template variable output, we pushed the grid output in our desired place in html.
  3. We have html meta tag for ‘csrf-token’, which is required by laravel for POST operations. Also added JavaScript code to pass CSRF-TOKEN in ajax request calls, as mentioned in Laravel docs.

For demo purpose, we slightly modified ‘laravel/resources/views/welcome.blade.php’

Step3: Setting Routes

The Last step in this tutorial is to set the routes to our controller. We will use both GET and POST routes as our grid uses both methods.

Note: The DataGrid does not rely on Eloquent ORM model of Laravel. It uses its own backend libraries.

Result: The Editable DataGrid for Laravel 11!

Next Actions:

Released Version 2.9

Welcome to the new release (version 2.9) of the Grid 4 PHP Framework. There are many updates in this version that we hope you will like, Following are some of the key highlights.

  • PHP 8.3 support
  • CodeIgniter v4 Integration
  • Using with Laravel v11
  • WordPress v6 Integration
  • Bootstrap v5 Integration
  • Drag-and-Drop Row Sorting, Effortlessly
  • Capture Digital Signatures with DataGrid
  • Badges and Dropdown rows
  • Rating plugin
  • New Html Input Types support: e.g. color, number, date
  • Export to MS-Word
  • UI and Design improvements
  • Security updates

CodeIgniter 4 Integration: We’ve made a quick walk-through how to integrate the smart PHP DataGrid with CodeIgniter framework.

Row Drag-and-Drop Sorting: To manage and organize your data in an intuitive and user-friendly manner.

WordPress6 Integration: We’ve published a new simplified tutorial on how to integrate Grid 4 PHP Framework with WordPress Sites.

Bootstrap5 Integration: Grid 4 PHP Framework is ready to use with Bootstrap5. Roll-out your next web-application with combining power of responsive PHP Data Grid and Bootstrap5 UI design.

Capturing Digital Signature: You can now take Digital Signatures using DataGrid and save it in the database.

Star Rating Plugin: Add a rating star plugin to be used as a column formatter.

Fixes:

  • Database layer library update
  • Toolbar button position, Autoheight update
  • Excel export library update
  • Better MS SQL Server FreeTDS support
  • Informix database fixes
  • Many reported bug fixes and updates.

This version will work on PHP v7 and onwards. For older PHP versions, v2.8.2 was the last stable release.

Next Actions:

PHP DataGrid for CodeIgniter

We’ve made a quick walk-through how to integrate the smart PHP DataGrid with CodeIgniter framework. For this, we have used:

  • Grid 4 PHP Framework 2.9
  • Latest version of CodeIgniter (v4+)
  • PHP 8 (can work on lower supported versions as well)

In this code we used MySQL, however you can use PHP DataGrid combination with almost all famous Database engines including Oracle, Microsoft SQL Server, DB2, Postgres, SQLite, Firebird, etc.

Steps:

Steps to integrate are very simple.

  1. Download CodeIgniter archive from Github repository and extract it in your public_html / htdocs / similar web public folder of your web server. Make sure it is showing the CI startup page.
  2. Download the Grid4PHP archive from our website. You can either use free OR paid version, Comparison is available here. Free version provides basic essential functions for evaluation purpose.
  3. Extract the Grid4PHP archive and move the ‘lib’ folder from archive to the ‘public’ folder of CodeIgniter.
  4. Replace the code of CI’s Controller app\Controller\Home.php with this sample controller code.
  5. In View, include the JS and CSS files and echo variable passed from controller. CI’s View welcome_message can be replaced with this sample view code.
  6. In Controller, make sure you set the database configuration (Line 9-14) and a table to fetch data (Line 45), according to your requirement. Refer lines in sample controller code.

Troubleshooting:

  • Getting “Whoops! We seem to have hit a snag. Please try again later”. If you see this message after setting up, please check the log file of CodeIgniter in “writable/logs” folder. It will tell the exact reason behind it.
  • Make sure you have “intl” and “curl” php extensions installed. They are required by CodeIgniter 4.
  • You can always open a support ticket for us.

Next Actions:

Using Grid 4 PHP Framework in WordPress

As popularity of WordPress is growing really fast, we’ve published a new simplified tutorial on how to integrate Grid 4 PHP Framework with WordPress Sites. WordPress misses a comprehensive Editable Table, DataGrid and a CRUD solution, so we’ve integrated it to solve the problem.

It allows using all features of our Data Grid inside WordPress and much simpler than previous implementations. Steps required to integrate are following:

Updated 30-July-2024: New revised tutorial supports:

  • PHP 8.3 and WordPress 6.4.3
  • DataGrid custom event handlers as well.

Step1: Download Free version or Buy package from our website (if not already done) and move “lib” folder from package in your WordPress root directory, and rename “lib” folder as “phpgrid”

and inside this folder the contents should be:

Step2: Install WordPress plugin “Code Snippets” from wordpress.org/plugins/code-snippets/ OR download from Github Repository and install manually.

Step3: Goto admin panel and click Add Snippet as in image. Add any title you like and in code section, copy paste this Sample Snippet Grid Code in code section shown below:

Step4: In this code, we have created a shortcode here same as class name: [phpgrid_users] and we will now place it on page where we want to show our Datagrid.

Result: Now Save the page and open / preview it, you will get the Datagrid.


Adding Grid in WordPress Admin Area
:

Following steps will be required to make shortcode available in admin area – plugin development.

Step1: Add admin_init & admin_footer hook along with others.

Step2: Select ‘Run Snippet everywhere’ after snippet code block.

Step3: Call do_shortcode() function where you want to show datagrid.

Result:

You can create more snippets by copying code from package demos and assign new unique class name for each grid which can be placed on your page/post of WordPress.

Let us know your feedback. If you have any questions, contact our support center.

Next Actions:

Active License Subscription customers can get free upgrade using this link.

SQL Server Integration Just Got Better with PHP Data Grid

Hello,

We’ve just added improved support to use our PHP Data Grid with MS SQL Server. The demo browser that comes with the product can now be tested with SQL Server database along with MySQL database.

To install demos with PHP and MS SQL Server, Download the package from our download page and then install the database from the MS SQL Server database script.

To connect MS SQL Server, you must have SQL Server Native driver for PHP installed on your environment. Next you can use one of the following connection settings to be set in config.php. For example:

// Using PDO
define("PHPGRID_DBTYPE","pdo");
define("PHPGRID_DBHOST","sqlsrv:Server=den1.mssql5.gear.host");
define("PHPGRID_DBUSER","testdb63");
define("PHPGRID_DBPASS","testpass");
define("PHPGRID_DBNAME","testdb63");

// Using PHP Native SQL Server Driver
define("PHPGRID_DBTYPE","mssqlnative");
define("PHPGRID_DBHOST","den1.mssql5.gear.host");
define("PHPGRID_DBUSER","testdb63");
define("PHPGRID_DBPASS","testpass");
define("PHPGRID_DBNAME","testdb63");

// Using OBDC Driver
define("PHPGRID_DBTYPE","odbc_mssql");
define("PHPGRID_DBHOST","Driver={SQL Server};Server=den1.mssql5.gear.host;Database=testdb63;");
define("PHPGRID_DBUSER","testdb63");
define("PHPGRID_DBPASS","testpass");
define("PHPGRID_DBNAME",null);

Troubleshooting:

Best way to troubleshoot database connection is to make an independent php file with just php-sqlserver connection code as shown in php manual. When it works, just put the verified configuration in config.php file of php data grid.

What Next:

Drag-and-Drop Row Sorting, Effortlessly

Hello,

We are thrilled to share an exciting new feature of ‘Row Drag-and-Drop Sorting’ to manage and organize your data in an intuitive and user-friendly manner. With this feature, you can now effortlessly rearrange data rows within your tables by simply dragging and dropping them into the desired position.

The todo-list demo is mobile friendly and drag drop feature can be used on mobile devices as well.

See Screencast below.

Mobile View:

The working demo can be checked online and inside full version package in demos/apps/todos.

Live Demohttps://www.gridphp.com/demo/demos/apps/todos.php

This feature is a part of our upcoming version 2.9.0 and active subscription customers can request free upgrade or renew your expired subscription using this link.

What Next:

Capture Digital Signatures with DataGrid

Hello,

You can now take Digital Signatures using DataGrid and save it in database along with other data. Bulk editing feature can also be used when updating Digital Signature. See screencast below.

The working demo can be checked online and inside full version package in demos/integration/signature.

Live Demo: https://www.gridphp.com/demo/demos/integrations/signature.php

Next Actions:

Active License Subscription customers can get free upgrade using this link.

Released Version 2.8

Welcome to the August 2021 release (version 2.8). There are many updates in this version that we hope you will like. It contains PHP 8 compatibility, UI Design Optimizations, Performance Optimizations, Security updates and Bug fixes. It also contains some new demos for better usability of data grid in your application. Highlights mentioned below.

Data Grid in Accordion Control

Now you can have multiple data grids inside accordion control. It’s best suited for multiple step process and to organize multiple modules on a single page.

Custom HTML Listing Layout

This feature allow you to display each record with customized layout with html code and fields placeholders.

Improved Database Table Editor

This tool enables you to quickly perform DML operations on a database defined in the code configuration.

RSS Reader using DataGrid

This demo loads the RSS feed into an array to be used as a data-source of data grid.

Data Import Progress Bar

Progress bar was a demanding feature when we importing large dataset.

Open Street Maps Integration

Like Google maps, you can also use Open Street maps and use the parameters of lat/lng from database using field placeholders.

Improved Tree Grid

Updates:

  • PHP 8.0 compatibility, updated related libraries
  • UI and Design improvements
  • Security updates: sanitizations added
  • Custom HTML layout on Datagrid List View
  • Demo to persist grid setting in database
  • Demo to integrate open street maps integration
  • Import feature now show progress-bar & column match probability setting while import mapping
  • Global search when multiple words typed will now narrow down searches
  • Optimized Tree grid Demo (parent selection via lookup dropdown)
  • Lookup option in dropdown (show lookup by just FK table, FK-id, FK-label)
  • Added demo for Read-only grid, Plain Html UI grid, Responsive grid with horizontal scroll

This also contains over 70 reported bug fixes and updates.

Integration with Code Igniter 4.0 and Laravel 8.0 is also in testing phase and will be released soon as a separate update.

Next Actions:

Active License Subscription customers can get free upgrade using this link.

PHP 8 Support

PHP 8 has been released some time ago and had some breaking changes. We’ve been hard at work behind the scenes to provide support for all our libraries so that upgrading to PHP 8 with Grid 4 PHP Framework is easy.

The licensed version update is available now and free version packaging is in progress which will be published soon.

Active License Subscription customers can get update using this link.