StartVader StartVader - 1 year ago 194
PHP Question

Moodle flexible_table sorting

I am using

Moodle 2.6
and already rewrote a table from
. I could not figure out, how the
is working.
I set everything as follows:

$table = new flexible_table('Car Bookings');
$table->define_baseurl(new moodle_url("/blocks/cars/view.php"));
'car name',
'plate number',
'pick-up date',
'tank date',
$table->sortable(true, 'carname');

I then add for the sorting:

if ($table->get_sql_sort()) {
$sort = ' ORDER BY '.$table->get_sql_sort();
} else {
$sort = '';

The table is rendering, but the sorting is not working, i.e the headers are "sorting"-I can click on them, but nothing happens. What I am missing?

Answer Source

You need to do the sorting manually. Something like this:

if ($orderby = $table->get_sql_sort()) {
    $sql .= ' ORDER BY ' . $orderby . ' ';

Have a look at the code in /user/index.php

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download