PHP code example of bytestechnolabs / datagrid

1. Go to this page and download the library: Download bytestechnolabs/datagrid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bytestechnolabs / datagrid example snippets


   Datagrid\DatagridServiceProvider::class,
   
 artisan storage:link

use Datagrid\Facades\DataGridFacade;
use Illuminate\Support\Facades\Session;

public function index()
{
    // Define the unique session key
    $sessionKey = config('datagrid.User_SessionKey');
    // Retrieve the selected columns from the session
    $columns = Session::get($sessionKey);
    // Use default columns if session data is not set
    if ($columns === null) {
        $columns = config('datagrid.users_columns');
        Session::put($sessionKey, $columns);
    }

    // Get all available columns
    $columnsAll = config('datagrid.users_columns');

    // Render the data grid
    $dataGrid = DataGridFacade::model(User::class)
        ->columns($columns)
        ->searchColumns($columns)
        ->columnsAll($columnsAll)
        ->paginate(10);

    return view('your blade file', ['dataGrid' => $dataGrid]);
}

// Define the unique session key
$sessionKey = config('datagrid.User_SessionKey');

// Retrieve the selected columns from the session
$columns = Session::get($sessionKey);

// Use default columns if session data is not set
if ($columns === null) {
    $columns = config('datagrid.users_columns');
    Session::put($sessionKey, $columns);
}

// Get all available columns
$columnsAll = config('datagrid.users_columns');

// Render the data grid
$dataGrid = DataGridFacade::model(User::class)
    ->columns($columns)
    ->searchColumns($columns)
    ->columnsAll($columnsAll)
    ->paginate(10);

return view('test', ['dataGrid' => $dataGrid]);

'users_columns' => [
    'id',
    'name',
    'email',
    'email_verified_at',
],

'User_unique_column' => 'email',

'User_SessionKey' => 'user_columns',

'User_has_edit_option' => false,

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    @