Welcome Guest, Not a member yet? Register   Sign In
table class remove ID field when displaying the table
#4

[eluser]InsiteFX[/eluser]
Hi R_Nelson

First you wil need a MY_Controller makes it easier to use the the Table Class!

MY_Controller - application/core/MY_Controller
Code:
class MY_Controller extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    
        $this->load->library('table');

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

            'thead_open'         => '<thead>',
            'thead_close'        => '</thead>',

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

            'tbody_open'         => '<tbody>',
            'tbody_close'        => '</tbody>',

            '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);
    }
}

Controller extended for the above MY_Controller
Code:
public function index()
    {
        // Setting headings for the table
        $this->table->set_heading('ID', 'Song', ,'Artisit', 'Actions');

        // $data will be what you pull from your database table!
        foreach ($data as $value => $key)
        {
            // Build actions links for editing and deleting records! you can do away with this part if your do not need it
            $actions = anchor("link_to_edit/edit/".$key['id']."/", "Edit") . anchor("link_to_delete/delete/".$key['id']."/", "Delete");

            // Adding a new row to table, remove any $key you do not need.
            $this->table->add_row($key['id'], $key['song'], $key['artisit'], $actions);
        }
    }

View
Code:
&lt;!-- Generate the table in the view. --&gt;
&lt;?php echo $this->table->generate();?&gt;

Note: If you need to redo the table $this->table->clear();

InsiteFX


Messages In This Thread
table class remove ID field when displaying the table - by El Forum - 04-03-2011, 11:34 AM
table class remove ID field when displaying the table - by El Forum - 04-03-2011, 04:33 PM
table class remove ID field when displaying the table - by El Forum - 04-03-2011, 06:36 PM
table class remove ID field when displaying the table - by El Forum - 04-03-2011, 07:17 PM
table class remove ID field when displaying the table - by El Forum - 04-03-2011, 08:30 PM
table class remove ID field when displaying the table - by El Forum - 04-03-2011, 08:42 PM
table class remove ID field when displaying the table - by El Forum - 04-03-2011, 09:48 PM
table class remove ID field when displaying the table - by El Forum - 04-03-2011, 09:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB