【问题标题】:How to adding sortable column in joomla 3.4如何在 joomla 3.4 中添加可排序的列
【发布时间】:2015-05-10 11:46:10
【问题描述】:

这是我的代码,但不工作,请告诉我我的问题是什么? 如何在 joomla 3.x 中添加可排序的列表 这篇文章对我没有帮助 joomla adding soratable columns

型号

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;
    }
}

查看.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);
}

查看/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>

【问题讨论】:

    标签: php joomla jquery-ui-sortable


    【解决方案1】:

    删除这些行,看看是否有帮助。 Joomla 应该为您处理所有这些。

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

    如果这不起作用,请尝试在Component Creator 中创建列表视图并从那里复制/粘贴代码。

    【讨论】:

      猜你喜欢
      • 2014-08-17
      • 2015-06-15
      • 1970-01-01
      • 2014-01-12
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多