https://github.com/masterfermin02/simple-data-grid
Simple Data Grid is a PHP package that provides an easy way to generate HTML tables from arrays of data
https://github.com/masterfermin02/simple-data-grid
array datagrid php table tailwindcss
Last synced: 7 months ago
JSON representation
Simple Data Grid is a PHP package that provides an easy way to generate HTML tables from arrays of data
- Host: GitHub
- URL: https://github.com/masterfermin02/simple-data-grid
- Owner: masterfermin02
- License: mit
- Created: 2023-12-27T19:38:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-24T16:18:50.000Z (about 2 years ago)
- Last Synced: 2025-01-29T11:22:03.817Z (over 1 year ago)
- Topics: array, datagrid, php, table, tailwindcss
- Language: PHP
- Homepage:
- Size: 91.8 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Simple Data Grid
[](https://packagist.org/packages/masterfermin02/simple-data-grid)
[](https://github.com/masterfermin02/simple-data-grid/actions/workflows/run-tests.yml)
[](https://packagist.org/packages/masterfermin02/simple-data-grid)
Simple Data Grid is a PHP package that provides an easy way to generate HTML tables from arrays of data. It supports custom headers, rows, CSS classes, and table properties.
## Installation
You can install the package via composer:
```bash
composer require masterfermin02/simple-data-grid
```
## Usage
Here's a basic example of how to use the Simple Data Grid:
```php
use Masterfermin02\SimpleDataGrid\SimpleGrid;
$headers = ['Name', 'Email', 'Phone'];
$rows = [
['John Doe', 'john@example.com', '123-456-7890'],
['Jane Doe', 'jane@example.com', '098-765-4321'],
];
echo SimpleGrid::fromArray($headers, $rows)->render();
```
This will generate an HTML table with the specified headers, rows, CSS class, and table properties.
## Mysql Database Support
This example assumes that you have a MySQL database running on localhost with a database named `mydatabase`, a table named `users`, and columns `id`, `name`, and `email`.
```php
mysqlQuery(
new MysqlQuery(
table: 'users',
columns: ['id', 'name', 'email'],
)
);
echo $grid->render();
```
## Add pagination
```php
itemPerPage(3)
->currentPage(
$_GET['page'] ?? 1
);
echo $grid->render();
echo (new PaginatorNav(
$grid
))->render();
```
In this example, `SimpleGrid::fromDatabase` is used to create a new `SimpleGrid` instance connected to a MySQL database. The `mysqlQuery` method is then used to execute a SELECT query on the `users` table, selecting the `id`, `name`, and `email` columns. The `render` method is finally called to generate the HTML for the data grid.
## Screenshots
[](https://github.com/masterfermin02/simple-data-grid/)
## Using laravel model
```php
get(),
)
->itemPerPage(3)
->currentPage(
$_GET['page'] ?? 1
);
echo $grid->render();
echo (new PaginatorNav(
$grid
))->render();
```
## Using laravel query builder
```php
select('id','name', 'email')->get(),
)
->itemPerPage(3)
->currentPage(
$_GET['page'] ?? 1
);
echo $grid->render();
echo (new PaginatorNav(
$grid
))->render();
```
## Using laravel eloquent cursor
```php
cursor(),
)
->itemPerPage(3)
->currentPage(
$_GET['page'] ?? 1
);
echo $grid->render();
echo (new PaginatorNav(
$grid
))->render();
```
## Testing
```bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Contributing
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
## Security Vulnerabilities
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
## Credits
- [Fermin](https://github.com/masterfermin02)
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
```
This `README.md` provides a brief description of the package, installation instructions, a usage example, and links to other important documents like the changelog, contributing guidelines, and license.