2015-05-10 4 views
0

Это мой код, но не работает, пожалуйста, сообщите мне, в чем моя проблема? как добавление сортировки таблицы столбцов в Joomla 3.x Эта статья не помогла мне joomla adding soratable columnsКак добавить сортируемый столбец в joomla 3.4

Модель

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

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> 

ответ

0

Удалите эти строки и посмотрите, помогает ли это. 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 и копировать/вставить код оттуда.

Смежные вопросы