Welcome Guest, Not a member yet? Register   Sign In
HTML Table Class proper use
#1

Hello
with a little of surprise I observed that the whole page of the guide here
https://codeigniter4.github.io/userguide...table.html
doesn't mention at all the words "model", "view" and nor "controller" :-(

there, a real full example may be really welcome (controller + view snippets)

So as principle I suppose that the code snippets in that pages should be used in a controller but I'm a bit confused about the view part, so I thank in advance for any kind clarification

In particular, I kindly ask how to properly use the HTML Table Class to display the results of my query in an HTML table, but displacing it in a PORTION of a view where in others portions of the same view, others queries will I output others kind of data (best practice for this, e.g like in a dashboard)

as plus (but this becomes off topic)
My final goal will be to provide also some sorting for the table' columns and when a new sorting happen, to have only the portion of the HTML table to be refreshed (HTMX?) . If you have any hint about this too, it would be great with many thanks in advance
Reply
#2

(This post was last modified: 04-21-2023, 07:50 PM by luckmoshy.)

Alright, as I got you, it is fine since CI always follows MVC rules and the HTML table is always a part of the VIEW from the controller. Here only thing I see is your own abstraction issue which I do mean CI4+ may not be accomplished for every one abstraction unless to offer some useful guidance on how to  .. as we see if you have read here

https://codeigniter4.github.io/userguide...index.html  and had tested it, I am sure it would help you go to the next step. You can see that you can implement it yourself in the controller and then pull it into your view.

You can also you Madel if you have read about model in its guidance

Personally, I use a CI HTML table with a view cell  https://codeigniter4.github.io/userguide...=view_cell it is real work and amazing. I don't know if you would be interested in...

o your question why don't you do this and pull in your normal view or view cell
PHP Code:
$table = new \CodeIgniter\View\Table();


$template = [
    'table_open'        => '<table border="1" 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>',
    'row_alt_end'        => '</tr>',
    'cell_alt_start'    => '<td>',
    'cell_alt_end'      => '</td>',
    'table_close'        => '</table>'
]; 
$table->setTemplate($template);

and last, IN HTMX you may try this may help you  https://github.com/michalsn/codeigniter-htmx
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#3

(This post was last modified: 04-21-2023, 11:09 PM by Corsari.)

Hi Luckmoshy
Thank you really much, today I'll try to dive in all the aspects you pointed out

And , also, I must tell you had read my mind, in fact I was wondering about if the HTML table class would have had sense in combination with CI cells 

Can you show a minimal example of how you implement it with a cell? Do you implement it with this feature https://codeigniter.com/user_guide/outgo...etup-logic ?

P.S. the second piece of code in the link is confusing me, because view_cell calls a method 'show' that is not clear to me where it comes from

PHP Code:
// app/Cells/RecentPosts.php
namespace App\Cells;

use 
CodeIgniter\View\Cells\Cell;

class 
RecentPosts extends Cell
{
    protected $posts;

    public function mount(?int $categoryId)
    {
        $this->posts model('PostModel')
            ->when($categoryId, function ($query$category) {
                return $query->where('category_id'$categoryId);
            })
            ->getRecent();
    }
}

// Called in main View:
<?= view_cell('RecentPosts::show', ['categoryId' => 5]); ?>




Thank you
Reply




Theme © iAndrew 2016 - Forum software by © MyBB