Moodle flexible_table 排序
Moodle flexible_table sorting
我正在使用 Moodle 2.6
并且已经将 table 从 html_table
重写为 flexible_table
。我不知道 sorting
是如何工作的。
我设置如下:
$table = new flexible_table('Car Bookings');
$table->define_baseurl(new moodle_url("/blocks/cars/view.php"));
$table->define_columns(array(
'carname',
'platenumber',
'pickupdate',
'tankdate',
'city',
'actions',
));
$table->define_headers(array(
'car name',
'plate number',
'pick-up date',
'tank date',
'city',
'actions',
));
$table->sortable(true, 'carname');
$table->collapsible(false);
然后我添加排序:
if ($table->get_sql_sort()) {
$sort = ' ORDER BY '.$table->get_sql_sort();
} else {
$sort = '';
}
table 正在渲染,但排序不起作用,即 headers 是 "sorting"-我可以点击它们,但没有任何反应。我缺少什么?
您需要手动进行排序。像这样:
if ($orderby = $table->get_sql_sort()) {
$sql .= ' ORDER BY ' . $orderby . ' ';
}
看看/user/index.php
中的代码
我正在使用 Moodle 2.6
并且已经将 table 从 html_table
重写为 flexible_table
。我不知道 sorting
是如何工作的。
我设置如下:
$table = new flexible_table('Car Bookings');
$table->define_baseurl(new moodle_url("/blocks/cars/view.php"));
$table->define_columns(array(
'carname',
'platenumber',
'pickupdate',
'tankdate',
'city',
'actions',
));
$table->define_headers(array(
'car name',
'plate number',
'pick-up date',
'tank date',
'city',
'actions',
));
$table->sortable(true, 'carname');
$table->collapsible(false);
然后我添加排序:
if ($table->get_sql_sort()) {
$sort = ' ORDER BY '.$table->get_sql_sort();
} else {
$sort = '';
}
table 正在渲染,但排序不起作用,即 headers 是 "sorting"-我可以点击它们,但没有任何反应。我缺少什么?
您需要手动进行排序。像这样:
if ($orderby = $table->get_sql_sort()) {
$sql .= ' ORDER BY ' . $orderby . ' ';
}
看看/user/index.php