简体   繁体   English

如何在joomla 3.4中添加可排序的列

[英]How to adding sortable column in joomla 3.4

This is my code but not working , please tell me what is my problem ? 这是我的代码,但是不起作用,请告诉我我的问题是什么? how to adding sortable column table in joomla 3.x This article did not help me joomla adding soratable columns 如何在joomla 3.x中添加可排序的列表本文不帮助我joomla添加可排序的列

Model 模型

class PwpModelPwp extends JModelLegacy {

    private $perPage;
    private $limitstart;
    private $pagination;


    public function __construct($config = array())
    {   
        $config['filter_fields'] = array(
            'nickname',
            'country'
        );
        parent::__construct($config);
    }

    protected function populateState($ordering = null, $direction = null) {
        parent::populateState('id', 'ASC');
    }

    public function listUsers(){
        $db = JFactory::getDbo();

        $this->perPage = 25;
        $this->limitstart=JRequest::getInt('limitstart',0);

        $query = $db->getQuery(true);
        $query->select("*")
        ->from("#__pwpusers")
        ->setLimit($this->limitstart.','.$this->perPage)
        ->order($db->escape($this->getState('list.ordering', 'id')).' '.
        $db->escape($this->getState('list.direction', 'DESC')));
        $query = $db->setQuery($query);
        $res = $db->loadObjectList();
        return $res;
    }
}

View.html.php View.html.php

class PwpViewPwp extends JViewLegacy {
protected $items;
protected $state;
public function display($tpl=null) {

    $items = $this->get('Items');
    $state = $this->get('State');
    $this->sortDirection = $state->get('list.direction');
    $this->sortColumn = $state->get('list.ordering');
    $task = JRequest::getVar('task');

    switch($task) {

        case "users":
            $tpl = "users";
            JToolBarHelper::addNew('pwp.addNew');
            JToolBarHelper::custom('pwp.delUser', 'delete.png', 'delete_f2.png', 'Delete', false);
            JToolBarHelper::back('Back');
            break;
    }
    parent::display($tpl);
}

view/default.php 查看/default.php

<?php
JHtml::_('behavior.formvalidation');
$model = $this->getModel('pwp');
$result = $model->listUsers();
?>
<script language="javascript" type="text/javascript">
function tableOrdering( order, dir, task )
{
    var form = document.adminForm;

    form.filter_order.value = order;
    form.filter_order_Dir.value = dir;
    document.adminForm.submit( task );
}
</script>
<form action="index.php?option=com_pwp&task=pwp.users" method="post" name="adminForm" id="adminForm" >
<table class="table table-striped" id="userList">
    <thead>
        <tr>
            <td width="1"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?=count( $result )?>);" /></td>
            <th width="1"> # </th>
            <th><?php echo JHTML::_( 'grid.sort', 'Nickname', 'nickname', $this->sortDirection, $this->sortColumn); ?>
            <th><?php echo JHTML::_( 'grid.sort', 'Country', 'country', $this->sortDirection, $this->sortColumn); ?>
        </tr>
    </thead>
    <tbody>
        <?php
        for($i=0;$i<count($result);$i++)
        {
            $row = $result[$i];
            $checked    = JHTML::_('grid.id', $i, $row->id);

            echo '
            <tr class="row'.$i.'">
                <td>'.$checked.'</td>
                <td>'.$i.'</td>
                <td><a href="'.JRoute::_('index.php?option=com_pwp&task=pwp.addUser&id='.$row->id.'').'">'.$row->nickname.'</a></td>
                <td>'.$row->country.'</td>
            </tr>';
        }
        ?>
    </tbody>
    <tfoot>
        <tr>
            <td colspan="6"><?php echo $model->showPagination(); ?></td>
        </tr>
    </tfoot>
</table>
<input type="hidden" name="option" value="com_pwp" />
<input type="hidden" name="task" value="pwp.<?=$_REQUEST['task'];?>" />
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
</form>

Remove these lines and see if it helps. 删除这些行,看看是否有帮助。 Joomla should handle all that for you. Joomla应该为您处理所有这一切。

<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />

If that does not work, try to create the list view in Component Creator and copy/paste the code from there. 如果这不起作用,请尝试在Component Creator中创建列表视图,然后从那里复制/粘贴代码。

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

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