Sort table in front end, any suggestion?

Hi everyone

Any suggestion about what can I use for sort a table generated in a foreach with cakephp 2? I know almost anything JavaScript, and I see that this can be an opportunity to practice it, but where do you recommend getting started?

A part of the table code:

            foreach ($list as $post):   ?>
                <tr id = "linePosts">
                    <?php if ($this->Session->read('logged') === true && $userRole === 'admin') { ?>
                        <td><?php echo $post['Post']['id']; ?></td>
                    <?php } ?>
                        <?php echo $this->Html->link($post['Post']['title'], array('action' => 'view', $post['Post']['id']));?>
                    <?php if (($this->Session->read('logged') === true) && ($userId === $post['Post']['user_id'] || $userRole === 'admin')) { ?>
                            <?php echo $this->Form->postLink(
                                array('action' => 'delete', $post['Post']['id']),
                                array('confirm' => 'VocĂȘ tem certeza?')
                            <?php echo $this->Html->link('Editar', array('action' => 'edit', $post['Post']['id']));?>
                    <?php }
                    else if (($this->Session->read('logged') === true)){ ?>
                    <?php } ?>    
                    $date = date_create($post['Post']['created']);
                    echo date_format($date, 'd/m/Y H:i:s');  ?></td>
            <?php endforeach;

You need to use any javascript sorting library to sort table data.

You can search on google or can visit this link jQuery tablesorter 2.0

Another option is a server fetched partial.

You can fetch your data to js variable (object, array), make sorting there and write function to render table from this data.