PHP code example of wpbones / wptables

1. Go to this page and download the library: Download wpbones/wptables 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/ */

    

wpbones / wptables example snippets

 copy


namespace WPKirk\Http\Controllers;

use WPKirk\WPTables\Html\WPTable;

class ExampleTable extends WPTable
{

  protected $name = 'Discos';

  public function getColumnsAttribute()
  {
    return [
      'id'          => 'Name',
      'description' => 'Description',
    ];
  }

  public function getItems( $args = [] )
  {

    $fake = [];

    for( $i = 0; $i < 20; $i++ ) {
      $fake[] = [
        'id' => "Example {$i}",
        'description' => 'Some description...'
      ];
    }

    return $fake;

  }
}
 copy
...
  public function load()
  {
    ExampleTable::registerScreenOption();
  }

  public function index()
  {
    $table = new ExampleTable();

    return WPKirk()
      ->view( 'dashboard.table' )
      ->with( 'table', $table );
  }
...


public function getCheckBoxValueAttribute( $item )
{
   return $item[ 'my_colum' ];
}

// or

public function getCheckBoxColumnNameAttribute()
{
   return 'my_colum';
}

 copy
...
  public function loadFluentExample()
  {
    WPTable::name( 'Books' )
           ->columns(
              [
                'id'          => 'Name',
                'description' => 'Description',
              ]
            )
           ->screenOptionLabel( 'Rows' )
           ->registerScreenOption();
  }

  public function indexFluentExample()
  {

    $items = [];

    for ( $i = 0; $i < 20; $i++ ) {
      $items[] = [
        'id'          => "Book {$i}",
        'description' => 'Some description...',
      ];
    }

    $table = WPTable::name( 'Books' )
                    ->singular( 'Book' )
                    ->plural( 'Books' )
                    ->columns(
                      [
                        'id'          => 'Name',
                        'description' => 'Description',
                      ]
                    )
                    ->setItems( $items );

    return WPKirk()
      ->view( 'dashboard.table' )
      ->with( 'table', $table );
  }