我在Joomla webapplication中添加了以下PHP代码。 这将创建一个来自用户组的所有用户的表。
如何使此表格可排序?
是否有一些Joomla / PHP代码或插件按名称订购此列表? 我可以添加一个参数来按任何列对其进行排序吗?
<?php
$teachers = JAccess::getUsersByGroup(10); //change number in the brackets
echo "<table class=\"table table-striped\">";
echo "<thead>";
echo "<tr>";
echo "<th>Name</th>";
echo "<th>Street</th>";
echo "<th>Zip</th>";
echo "<th>City</th>";
echo "<th>Phone</th>";
echo "<th>Email</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
foreach($teachers as $user_id) {
$user = JFactory::getUser($user_id);
$profile = JUserHelper::getProfile($user->id);
echo "<tr>";
echo "<td>".$user->name."</td>";
echo "<td>".$profile->profile['address1']."</td>";
echo "<td>".$profile->profile['postal_code']."</td>";
echo "<td>".$profile->profile['city']."</td>";
echo "<td>".$profile->profile['phone']."</td>";
echo "<td>".$user->email."</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
答案 0 :(得分:3)
e.g。 如果你想让它成为标题可排序使用代码,如下面添加表格标题
<?php echo JHTML::_('grid.sort', JText::_('TITLE'), 'title',
$this->lists['order_Dir'], $this->lists['order'] ); ?>
并在modal中使用以下函数在SQL中构建where子句。
getUserStateFromRequest(
$option.'filter_order_Dir', 'filter_order_Dir', 'ASC'));
以上功能将根据用户选择返回ASC或DSC
JHTML和JHTMLGRID是构建交互式表的有用类
details第279页
答案 1 :(得分:2)
我认为最简单的方法是使用jquery或使用jquery插件。您可以使用DataTables或Tablesorter,它们是可以放置该功能的jquery插件。
答案 2 :(得分:1)
我假设你希望表在客户端可以排序,这意味着你需要一些Javascript代码。有一些jquery库可以做到这一点(比如DataTables),但是也有Joomla特定的扩展,就像http://www.tabulizer.com的Tabomizer for Joomla有许多排序选项一样,你还可以避免任何jQuery与其他扩展冲突。这是一个排序演示http://www.tabulizer.com/index.php/support-menu/tabulizer-tips/63-sort-second-row
答案 3 :(得分:0)
您还可以使用直接为Joomla开发的plugin Szaki Table(目前可用于J!2.5和J!3.x)。 看看它,它是功能强大且高度可定制的工具。