简体   繁体   English

如何使Joomla表可排序?

[英]How to make a Joomla Table sortable?

I have added following PHP code in my Joomla webapplication. 在我的Joomla Web应用程序中添加了以下PHP代码。 This will create a table of all users from a User Group . 这将创建一个用户组中所有用户

How Can I make this table sortable? 如何使该表可排序?

Is there some Joomla/PHP code or plugin to order this list by Name? 是否有一些Joomla / PHP代码或插件可以按名称排序此列表? Can I add a parameter to sort this by any column? 我可以添加参数以按任何列对它进行排序吗?

<?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>";
?>

eg if you want it make title sortable use code similar like follwing to add table headers 例如,如果您希望它使标题可排序,则使用类似下面的代码来添加表头

  <?php echo JHTML::_('grid.sort', JText::_('TITLE'),  'title',
  $this->lists['order_Dir'],   $this->lists['order'] ); ?>

and use following function in modal to build your where clause in SQL. 并在模式中使用以下函数在SQL中构建where子句。

  getUserStateFromRequest(
  $option.'filter_order_Dir', 'filter_order_Dir', 'ASC'));

above function will return you the ASC or DSC based upon user choice 上述功能将根据用户选择返回ASC或DSC

JHTMLand JHTMLGRID are useful classes to build interactive tables JHTML和JHTMLGRID是用于构建交互式表的有用类

details page 279 详情页279

I think the easiest way would be to use jquery or use a jquery plugin. 我认为最简单的方法是使用jquery或使用jquery插件。 You can use DataTables or Tablesorter , they are jquery plugins that would put that feature. 您可以使用DataTablesTablesorter ,它们是将具有该功能的jquery插件。

I assume you want the table to sortable on the client side, which means you will need some Javascript code. 我假设您希望表在客户端可排序,这意味着您将需要一些Javascript代码。 There are some jquery libraries out there that do that (like DataTables), but there also Joomla specific extensions that do exactly that, like Tabulizer for Joomla at http://www.tabulizer.com with many sorting options, plus you avoid any jQuery conflicts with other extensions. 有一些jquery库可以做到这一点(例如DataTables),但也有Joomla特定扩展确实可以做到这一点,例如http://www.tabulizer.com上的Tabulizer for Joomla,它具有许多排序选项,另外还要避免使用任何jQuery与其他扩展名冲突。 Here is a sorting demo http://www.tabulizer.com/index.php/support-menu/tabulizer-tips/63-sort-second-row 这是一个排序演示http://www.tabulizer.com/index.php/support-menu/tabulizer-tips/63-sort-second-row

You can also use plugin Szaki Table developed directly for Joomla (currently available for J! 2.5 and J! 3.x). 您还可以使用直接为Joomla开发的插件Szaki Table (当前可用于J!2.5和J!3.x)。 Check it out, it's powerful and highly customizable tool. 检查一下,它是功能强大且高度可定制的工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM