Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Table generation module for Kohana PHP

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 classes
Octocat-spinner-32 tests
Octocat-spinner-32 views
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LICENSE.md
Octocat-spinner-32 README.md
Octocat-spinner-32 RELEASENOTES.md
Octocat-spinner-32 phpunit.xml
README.md

Grid

A tabular data presentation tool.

Quick Start

$grid = new Grid;
$grid->link()->action('entries/add')->text('Add New Entry');
$grid->column()->field('id')->title('Entry ID');
$grid->column()->field('title')->title('Entry Title');
$grid->column('date')->title('Creation Date');
$grid->column('action')->title('Edit')->url('entries/edit')->text('edit');
$grid->data($dataset);
echo $grid;

Setting up a Grid

There are 5 steps for creating a grid.

  1. Instantiate a grid object
  2. Specify action links (if any)
  3. Specify columns
  4. Add data
  5. Render the grid

Specifying Action Links

The grid library allows for links to be printed at the top and bottom of a grid table. Typical usage includes "add a new entry" and "edit the selected" links.

Links are specified by the Grid Library's link() method, which returns a link object. The argument of the link() method specifies the type of link, either text (default), button, or submit. Attributes of a link object are specified by calling a function by the name of the attribute, passing the value as an argument.

All links have the following attributes:

action : the path (or route) for the link text : the text to display for the link

Text Link

$grid->link()->action('controller/method')->text('Link Text');
// OR
$grid->link('text')->action('controller/method')->text('Link Text');

Will produce Link Text

Button Link

$grid->link('button')->action('controller/method')->text('Link Button');

Will produce Link Button

Submit Link

$grid->link('submit')->action('controller/method')->text('Link Submit');

Will produce

Specifying Columns

The grid library allows for columns to be defined. The columns specify what fields from each dataset record will be printed, and how it will be printed.

Columns are specified by the Grid Library's column() method, which returns a column object. The argument of the column() method specifies the type of column (default is text). Attributes of a column object are specified by calling a function by the name of the attribute, passing the value as an argument.

All columns have the following attributes:

field : the field of the dataset record to print title : the column heading

Text Column

$grid->column()->title('Name')->field('name');
// OR
$grid->column('text')->title('Name')->field('name');

Will produce

... Name ... ... <?php echo $record->name; ?> ...

Additional attributes include:

callback : a callback function to execute prior to printing

Date Column

$grid->column('date')->title('Created')->field('created');

Extends text columns to pass the value of $record->$field through the PHP date() function.

Additional attributes include:

format : a PHP date format string to use as the first parameter for date()

The field attribute defaults to "date".

Action Column

$grid->column('action')->title('Details')->url('controller/method')->field('id')->text('view');
// OR
$grid->column('action')->title('Details')->route('default')->params(array('controller'=>'controller', 'action'=>'method'))->param('id')->text('view');

Will produce

... Details ... ...
Something went wrong with that request. Please try again.