Спасибо за ссылку! Я видел это мануал! Но увы пока не пашет!
В своём тестовом компоненте я пишу код модели mycomponents.php
<?php
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
/**
* HelloWorlds Model
*/
class MycomponentModelMycomponents extends JModelList
{
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select('*');
// From the hello table
$query->from('#__mycomponent');
$orderCol = $this->state->get('list.ordering');
$orderDirn = $this->state->get('list.direction');
$query->order($db->getEscaped($orderCol.' '.$orderDirn));
return $query;
}
protected function populateState($ordering = null, $direction = null)
{
parent::populateState('name', 'asc');
}
}
Затем в виде дописываю.
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
/**
* HelloWorlds View
*/
class MycomponentViewMycomponents extends JView
{
/**
* HelloWorlds view display method
* @return void
*/
function display($tpl = null)
{
// Get data from the model
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$state = $this->get('State');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Assign data to the view
$this->items = $items;
$this->pagination = $pagination;
$this->state = $state;
// Set the toolbar
$this->addToolBar();
// Display the template
parent::display($tpl);
// Set the document
$this->setDocument();
}
/**
* Setting the toolbar
*/
protected function addToolBar()
{
JToolBarHelper::title(JText::_('COM_HELLOWORLD_MANAGER_HELLOWORLDS'), 'mycomponent');
JToolBarHelper::deleteListX('', 'mycomponents.delete');
JToolBarHelper::editListX('mycomponent.edit');
JToolBarHelper::addNewX('mycomponent.add');
JToolBarHelper::custom('mycomponents.publish', 'publish.png', 'publish_f2.png','JTOOLBAR_PUBLISH');
JToolBarHelper::custom('mycomponents.unpublish', 'unpublish.png', 'unpublish_f2.png', 'JTOOLBAR_UNPUBLISH');
}
/**
* Method to set up the document properties
*
* @return void
*/
protected function setDocument()
{
$document = JFactory::getDocument();
$document->setTitle(JText::_('COM_HELLOWORLD_ADMINISTRATION'));
}
}
А после в default_body.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted Access');
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
JHtml::_('behavior.tooltip');
JHtml::_('script','system/multiselect.js', false, true);
$user = JFactory::getUser();
$userId = $user->get('id');
$listOrder = $this->state->get('list.ordering');
$listDirn = $this->state->get('list.direction');
$canOrder = $user->authorise('core.edit.state', 'com_mycomponents.category');
$saveOrder = $listOrder == 'a.ordering';
?>
<?php foreach($this->items as $i => $item):
$ordering = ($listOrder == 'a.ordering');
$item->cat_link = JRoute::_('index.php?option=com_mycomponents&extension=com_mycomponents&task=edit&type=other&cid[]='. $item->catid);
$canCreate = $user->authorise('core.create', 'com_mycomponents.category.'.$item->catid);
$canEdit = $user->authorise('core.edit', 'com_mycomponents.category.'.$item->catid);
$canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out==$user->get('id') || $item->checked_out==0;
$canChange = $user->authorise('core.edit.state', 'com_mycomponents.category.'.$item->catid) && $canCheckin;
?>
<tr class="row<?php echo $i % 4; ?>">
<td>
<?php echo $item->id; ?>
</td>
<td>
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td>
<a href="<?php echo JRoute::_('index.php?option=com_mycomponent&view=mycomponent&layout=edit&id='.(int) $item->id); ?>"><?php echo $item->name; ?></a>
</td>
<td>
<?php echo JHtml::_('jgrid.published', $item->published, $i, 'mycomponents.', $canChange, 'cb', $item->publish_up, $item->publish_down); ?>
</td>
<td class="order">
<?php if ($canChange) : ?>
<?php if ($saveOrder) : ?>
<?php if ($listDirn == 'asc') : ?>
<span><?php echo $this->pagination->orderUpIcon($i, (@$this->items[$i-1]->catid == $item->catid), 'banners.orderup', 'JLIB_HTML_MOVE_UP', $ordering); ?></span>
<span><?php echo $this->pagination->orderDownIcon($i, $this->pagination->total, (@$this->items[$i+1]->catid == $item->catid), 'banners.orderdown', 'JLIB_HTML_MOVE_DOWN', $ordering); ?></span>
<?php elseif ($listDirn == 'desc') : ?>
<span><?php echo $this->pagination->orderUpIcon($i, (@$this->items[$i-1]->catid == $item->catid), 'banners.orderdown', 'JLIB_HTML_MOVE_UP', $ordering); ?></span>
<span><?php echo $this->pagination->orderDownIcon($i, $this->pagination->total, (@$this->items[$i+1]->catid == $item->catid), 'banners.orderup', 'JLIB_HTML_MOVE_DOWN', $ordering); ?></span>
<?php endif; ?>
<?php endif; ?>
<?php $disabled = $saveOrder ? '' : 'disabled="disabled"'; ?>
<input type="text" name="order[]" size="5" value="<?php echo $item->ordering;?>" <?php echo $disabled;?> class="text-area-order" />
<?php else : ?>
<?php echo $item->ordering; ?>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
И уже в шапке дописываю код default_head.php
<?php echo JHtml::_('grid.sort', 'name', 'name', $listDirn, $listOrder); ?>
поля
<input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
Тоже присутствуют! Но сортировка не работает, никаких ошибок нет. Мне кажется тут что то с видом или моделью.
Может подскажешь что тут не так, я вот пробую щас посмотреть в стандартных компонентах, но пока безуспешно.