elxisGrid

by Elxis Team

Generate dynamic tables with filtering, search, sorting and other cool features.

Elxis grid allows you to easily generate dynamic tables with filtering, search, sorting and other cool features. elxisGrid is a PHP API that uses Flexigrid and jQuery in the backend but can be changed at any time without having to change the implementation code due to the Elxis API. The Flexigrid javascript class used by Elxis is an improved by Ioannis Sannos version with RTL support, task setting and data filtering capabilities.

General usage


//Include the grid class
elxisLoader::loadFile('includes/libraries/elxis/grid.class.php');
//Initiate the grid instance. Optionally provide the element (table) id to which the grid will be applied to and the grid table title.
$grid = new elxisGrid('routes', $eLang->get('ROUTING'));
//...do stuff...
//display the grid
$grid->render();

Set grid options

Method setOption allows you to set/overwrite grid options.

public function setOption($option, $value);

Available options are:

  • element The id of the grid table (can also be set in the constructor).
  • title A title (optional) that will be displayed in the top of the table (optional - can also be set in the constructor)
  • url The URL the grid will load the data from.
  • datatype json/xml - the method of the ajax request to load the data.
  • sortname The name of the default sorting column
  • sortorder asc/desc - The default sorting order
  • usepager true/false - Wether to display paging or not
  • userp true/false - Wether to display the option to set the number of rows per page or not
  • resizable true/false - Wether the columns will be resizable or not
  • showtabletogglebtn true/false - Wether the table will be able to toggle on and off.
  • showtogglebtn true/false - Wether the columns will be able to toggle on and off.
  • singleselect true/false - Not used
  • rp The default number of rows per page (10 by default).
  • width Grid table width. Can be an integer (pixels) or 100%.
  • height Grid table height. Can be an integer (pixels) or auto.
  • dir ltr/rtl. This is set automatically on the constructor depending on the current language's direction. So normally, you never have to set it.

Example

$grid->setOption('sortname', 'location');
$grid->setOption('width', 700);

Add columns to the grid

Method addColumn allows you to add columns to the grid. The only required option is the column's title. $filteroptions can also be declared later with the addFilter method.

public function addColumn($title, $name='', $width=140, $sortable=true, $align='auto', $filteroptions=array()) {

Example

$grid->addColumn($eLang->get('SOURCE'), 'rbase', 180, true, 'auto');
$grid->addColumn($eLang->get('ACTIONS'), 'ractions', 100, false, 'auto');
$filters = array(
'' => $eLang->get('ANY'),
'cmp' => 'Component',
'dir' => 'Directory',
'page' => 'Page'
);
$grid->addColumn($eLang->get('TYPE'), 'rtype', 140, true, 'auto', $filters);

The sum of the widths of all columns in standard Elxis grid implementations are not greater than 980 pixels inorder to support a minimum screen resolution of 1024x768 pixels.


Add buttons

Adds a button. When the button is clicked the javascript function set in the $onpress attribute (optional) is executed. CSS class $class can be empty or add, delete, edit, toggle, filter, and more.

public function addButton($title, $task='', $class='', $onpress='');

Add separator

Adds a vertical line (separator) in the grid's buttons area. Use it to separate your buttons into groups.

public function addSeparator($bool=true)

Add search

Set searchable elements.

public function addSearch($title, $name, $isdefault=false)

Example

$grid->addSearch($eLang->get('TYPE'), 'rtype', false);
$grid->addSearch($eLang->get('SOURCE'), 'rbase', true);

Add filter

Adds a filter in the grid's search area. See also the addColumn method.

public function addFilter($title, $name, $options=array())

Example

$grid->addFilter(
$eLang->get('SOURCE'),
'rsource'
array(
'' => $eLang->get('ANY'),
't1' => 'test 1',
't2' => 'test 2',
't3' => 'test 3'
)
);

Display the grid

When finish configuring your grid use the render method to generate and output it's HTML.

public function render()

Example

$grid->render();

It has been read 4475 times
elxisPlugin
Previous article
elxisPlugin
elxisParameters
Next article
elxisParameters

You are free to copy, distribute and transmit the articles in this site for non-commercial purposes.
Creative Commons 3.0