Welcome Guest, Not a member yet? Register   Sign In
Codeigniter HTML Table Class, adding custom cell
#1

[eluser]Ficoder[/eluser]
Hi,
Here is the example code what i used:

application/controllers/site.php
Code:
<?php

class Site extends Controller {
    
    function index()
    {
        $this->load->library('pagination');
        $this->load->library('table');
        
        //$this->table->set_heading('Id', 'The Title', 'The Content');
        
        $config['base_url'] = 'http://localhost:8888/ci/index.php/site/index';
        $config['total_rows'] = $this->db->get('data')->num_rows();
        $config['per_page'] = 10;
        $config['num_links'] = 20;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';
        
        $this->pagination->initialize($config);
        
        $data['records'] = $this->db->get('data', $config['per_page'], $this->uri->segment(3));
        
        $this->load->view('site_view', $data);
        
    }
    
}

application\views\site_view.php

Code:
<!DOCTYPE html>

&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;
    &lt;title&gt;untitled&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
     <div id="container">
        <h1>Super Pagination with CodeIgniter</h1>
        
        &lt;?php echo $this->table->generate($records); ?&gt;
        &lt;?php echo $this->pagination->create_links(); ?&gt;
     </div>
&lt;/body&gt;
&lt;/html&gt;

This works great! But... I wan't to add two custom cells to every row, so i can Delete or Modify every row from link. And of course every link has to contain SQL entry unique ID. But is it possible to add custom cells in this situation, or is my only way to throw "HTML Table class" to trash bin and write all "manually"?
#2

[eluser]zackhovatter[/eluser]
http://ellislab.com/codeigniter/user-gui...table.html

Check out 'make_columns'. That won't let you put the unique ID in though.
#3

[eluser]InsiteFX[/eluser]
It is best to create a MY_Controller to do the following!

Credit to Adam Griffiths Fresh CMS, which is no longer avaiable on his web site.

Table Template placed into a MY_Controller
Code:
/**
* NOTE: Change Controller to CI_Controller if using CI 2.0
* Also for CI 2.0 The Table Template is different!
*/

class MY_Controller extends Controller
{

     function MY_Controller()
     {
         parent::Controller();

         $this->load->library('table');

         $tmpl = array (
             'table_open'          => '<table border="0" cellpadding="4" cellspacing="0">',

             'heading_row_start'   => '<tr>',
             'heading_row_end'     => '</tr>',
             'heading_cell_start'  => '<th>',
             'heading_cell_end'    => '</th>',

             'row_start'           => '<tr>',
             'row_end'             => '</tr>',
             'cell_start'          => '<td>',
             'cell_end'            => '</td>',

             'row_alt_start'       => '<tr class="alt">',
             'row_alt_end'         => '</tr>',
             'cell_alt_start'      => '<td>',
             'cell_alt_end'        => '</td>',

             'table_close'         => '</table>'
         );

         $this->table->set_template($tmpl);
     }

}

A Page Controller, To add Delete or Modify every row from link.
Code:
// ------------------------------------------------------------------------

    /**
     * manage - method.
     *
     * @access    public
     * @param    string
     * @return    string    void
     */
    function manage()
    {
         // List the pages.
        $data = $this->pages->pages();

        // Setting headings for the table.
        $this->table->set_heading('Title', 'Slug', 'Actions');
        
        foreach ($data as $value => $key)
        {
            // Build the custom actions links.
            $actions = anchor("admin/pages/edit/".$key['id']."/", "Edit") . anchor("admin/pages/delete/".$key['id']."/", "Delete");

            // Adding a new table row.
            $this->table->add_row($key['title'], $key['slug'], $actions);
        }

        // Load the view.
        $this->load->view('pages/manage');
    }

Code should give you an idea of how it is done.

InsiteFX
#4

[eluser]ericrjones1[/eluser]
I always like to set my own header and rows with the Table library.

Code:
$this->table->set_heading('Column 1', 'Column 2', 'Column 3', 'Column 4;');

// Assuming $value is an array
foreach ($data as $value) {
    $this->table->add_row(
        $value['A'],
        $value['B'],
        $value['C'],
        $value['D']
    );
}

echo $this->table->generate();

This usually allows me to create the table that I want.
This usually allows me to create the table exactly how I want it to be.
#5

[eluser]InsiteFX[/eluser]
If you read the code you would see that it is setting the heading!

InsiteFX
#6

[eluser]ericrjones1[/eluser]
Your right. My mistake.




Theme © iAndrew 2016 - Forum software by © MyBB