PHP Classes

File: usage.md

Recommend this page to a friend!
  Classes of Joubert RedRat   PHP AJAX Table   usage.md   Download  
File: usage.md
Role: Documentation
Content type: text/markdown
Description: Example script
Class: PHP AJAX Table
Load HTML tables dynamically using AJAX
Author: By
Last change:
Date: 7 years ago
Size: 2,002 bytes
 

Contents

Class file image Download

Usage

AjaxTable is separated in two steps, configuration for build table and response after ajax request.

Configuration

For configuration, is required to instanciate Conf to put all configuration, as below:

$Conf = new VectorDev\AjaxTable\Conf(base_url(['user', 'ajax-list']));

Conf will store all the information to generate a json for js lib

To create columns for your table, you will need to instanciate Column with information that you need to display.

$ColumnName = new VectorDev\AjaxTable\Column('username', 'Username');
$ColumnEmail = new VectorDev\AjaxTable\Column('email', 'E-mail');
$ColumnAge = new VectorDev\AjaxTable\Column('age', 'Age');

Column will store all the information about your table column.

After this, you need to add Column to your configuration.

$Conf->addColumn($ColumnName);
$Conf->addColumn($ColumnEmail);
$Conf->addColumn($ColumnAge);

To finish, you will build json configuration for AjaxTable js lib.

<script>
    jQuery().ready(function(){
        $('#table').ajaxTable(<?php echo $Conf->getJson(); ?>);
    });
</script>

And done, your table is now configurated to work as ajaxtable to request and print data.

Response

For response, is required to work with Response, Row and Cell classes to get request, work with data and response to view.

$Response = new VectorDev\AjaxTable\Response();
$Response->setRowsTotal($total_rows);

$limit = $Response->getLimitForSql(); // AjaxTable automatic build array for your use directly in your query
$order = $Response->getOrderByForSql(); // AjaxTable automatic build array with order by too

foreach($all_data as $data) {
	$CellUsername = new VectorDev\AjaxTable\Cell($data['user_username']);
	$CellEmail = new VectorDev\AjaxTable\Cell($data['user_mail']);
	$CellAge = new VectorDev\AjaxTable\Cell($data['user_age']);
	
	$Row = new VectorDev\AjaxTable\Row($CellUsername, $CellEmail, $CellAge);
	$Response->addRow($Row);
}

$Response->returnRequest();