Skip to content
amitaymolko edited this page Aug 13, 2013 · 17 revisions

Note: If you are using PHP 5 you can use method chaining for more compact syntax. This is described here: Method Chaining
Click here for more info: http://ellislab.com/codeigniter/user-guide/database/active_record.html

$this->datatables->select($columns);

Sets which columns to fetch from the specified table.

$this->datatables->select('id, name, age, gender');

*This function also accepts an optional second parameter. Click here for more info: http://ellislab.com/codeigniter/user-guide/database/active_record.html

$this->datatables->from($table);

Sets the primary table in which data will be fetched from.

$this->datatables->from('mytable');

$this->datatables->join($table, $fk, [$type]);

Sets join statement variables. If you want DataTables to include data from another table, you can define an a table along with its columns and foreign key relationship.

$this->datatables->join('mystates', 'mycountries.state_id = mystates.id', 'left');

*This function also accepts an optional third parameter for specifying the join type.

$this->datatables->where();

Sets filtering variable to facilitate custom filters. For additional filtering conditions, the WHERE clause works like CodeIgniter's. So you can do statements like:

$this->datatables->where('id', '5');
$this->datatables->where('age >', '25');
$this->datatables->where('position != "admin"');
$array = array('name' => 'J%', 'status' => 'Single');
$this->datatables->where($array);

$this->datatables->filter();

Sets filtering variable to facilitate custom filters. Adds "(filtered from xxx total entries)" to datatables. Same usage with 'where()' method.

$this->datatables->add_column($column, $content, [$match_replacement]);

Sets additional column variables to facilitate custom columns. You can also make your own custom column definitions via the following syntax: *match_replacement is optional only needed if you have $1 to $n matches in your content pattern

$this->datatables->add_column('edit', '<a href="profiles/edit/$1">EDIT</a>', 'id');

$this->datatables->edit_column($column, $content, $match_replacement);

Sets additional column variables for editing columns. You can also make your own custom column definitions via the following syntax: *match_replacement is needed in order to replace $1 to $n matches in your content pattern

$this->datatables->edit_column('username', '<a href="profiles/edit/$1">$2</a>', 'id, username');

$this->datatables->unset_column($column);

$this->datatables->generate([$output], [$charset]);

Builds all the necessary query segments and performs the main query based on results set from chained statements.
*optional parameter output (default is json) can be set to 'raw' to return a non-paginated array of the aaData and sColumns
*optional parameter charset (default is UTF-8) is used when working with non utf-8 characters for json outputs (may decrease performance and be unstable)

$this->datatables->generate();
$this->datatables->generate('json', 'ISO-8859-1');
$results = $this->datatables->generate('raw');
$data['aaData'] = $results['aaData'];
$data['sColumns'] = $results['sColumns'];
$this->load->view('downloads/csv', $data);