Welcome Guest, Not a member yet? Register   Sign In
Fast HTML5 Table using mytable library
#1

[eluser]cPage[/eluser]
What we want is to generate a html 5 or xhtml table rapidly. I took users from database for the example.

Controller
Code:
class Users extends CI_Controller
{
public function index()
{
  $this->load->library('mytable');
  $this->load->model('user_model');
  $result = $this->user_model->get_all();
  $row = 0;
  foreach ($result as $n=>$recordset)
  {
   $row++;
   $column = 0;
   foreach($recordset as $field=>$value)
   {
    $this->mytable->set(1,0,++$column,$field);
    $this->mytable->set(1,$row,$column,$value);
   }
  }
  $this->mytable->maxRecPage = 15;
  $this->mytable->caption = 'Users';
  $dataview['tblUser'] = $this->mytable->create_table(1,$row,$column,array('class'=>'tblCss'),TRUE,TRUE);
  $this->load->view('users',$dataview);
}
}

View
Code:
<div id="container">
&lt;?php
echo $tblUser;
?&gt;
</div>

Note : In the controller, you can get any value by coordinate and use them as a 3D grid. [table][row][column]
This example below mean get value at table 1, row 1, column 1.
Code:
$value = $this->mytable->get(1,1,1);

You can also retrieve all data, including field name into an array.
Fields names are at table[n], row[0], column[n]
Code:
$array_of_table_users = $this->mytable->data();
Or an entire data object like this:
Code:
$instance_of_table_users = $this->mytable->objet();

More... Once the html table is create. Ajax or Jquery can access all the td's from the html table by using is ID.
Each cell of the table have an ID. For example the cell [1][1][1] value is in <td id="td111">...</td>.

Mytable.php must be placed into application/libraries folder.

Mytable.php




Theme © iAndrew 2016 - Forum software by © MyBB