Reputation: 23
I'm developing a MVC component for Joomla! 2.5 and I want to add some sortable columns in my backend. For this goal I've tried to do the next:
http://docs.joomla.org/Adding_sortable_columns_to_a_table_in_a_component
And I got an error "View not found [name, type, prefix]". In this case I have looking for a solution and I find the next:
http://forum.joomla.org/viewtopic.php?p=2638695
Following those indications I have removed the "action" of my "form". In this case my column is sortable, but another problem arises. If I remove the "action" of my "form" then "edit buttom" of my toolbar does not work.
I think there must be another solution because I need working "edit buttom" and sortable column also. I've looking for some similar question here and I've applied the following information:
How to add sortable columns in a Joomla component (table), both ASC and DESC with an arrow
&
Joomla 2.5 -Adding sortable columns to a table in a component
But my problem persits. What can I do?? Thank you.
MY RELEVANT SOURCE CODE IS THE NEXT:
com_inscripciones/admin/models/anuals.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
/**
* Inscripciones List Model
*/
class InscripcionesModelAnuals extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'nombre',
'fecha_nac',
'reserva'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
parent::populateState('id', 'asc');
}
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
*/
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select('id,nombre,apellidos,nif,fecha_nac,reserva,validacion,clave');
// From the hello table
$query->from('#__anual');
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'nombre')).' '.$db->escape($this->getState('list.direction', 'ASC')));
return $query;
}
}
?>
com_inscripciones/admin/views/anuals/view.html.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
/**
* Anuals View
*/
class InscripcionesViewAnuals extends JView
{
/**
* display method of Inscripciones view
* @return void
*/
function display($tpl = null)
{
// Get data from the model
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$state = $this->get('State');
$this->sortDirection = $state->get('list.direction');
$this->sortColumn = $state->get('list.ordering');
// 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;
// Set the toolbar
$this->addToolBar();
// Display the template
parent::display($tpl);
}
/**
* Setting the toolbar
*/
protected function addToolBar()
{
JToolBarHelper::title(JText::_('Inscripciones Manager: Curso Anual'), 'inscripciones');
JToolBarHelper::spacer('10');
JToolBarHelper::divider();
JToolBarHelper::spacer('10');
JToolBarHelper::editList('anual.edit');
JToolBarHelper::spacer('10');
JToolBarHelper::divider();
JToolBarHelper::spacer('10');
JToolBarHelper::deleteList('¿Desea eliminar esta inscripción?', 'anuals.delete');
JToolBarHelper::spacer('20');
}
}
?>
com_inscripciones/admin/views/anuals/tmpl/default.php
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
?>
<form action="<?php echo JRoute::_('index.php?option=com_inscripciones&view=anuals$layout=default'); ?>"method="post" name="adminForm"id="inscripciones-form">
<table class="adminlist">
<thead>
<tr>
<th width="5">
<?php echo JText::_('ID'); ?>
</th>
<th width="20">
<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
</th>
<th>
<?php echo JHtml::_('grid.sort', 'NOMBRE', 'nombre', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JText::_('APELLIDOS'); ?>
</th>
<th>
<?php echo JText::_('NIF'); ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'FECHA NAC.', 'fecha_nac', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'RESERVA', 'reserva', $this->sortDirection, $this->sortColumn); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3"></td>
</tr>
</tfoot>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2; ?>">
<td>
<?php echo $item->id; ?>
</td>
<td>
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td>
<?php echo $item->nombre; ?>
</td>
<td>
<?php echo $item->apellidos; ?>
</td>
<td>
<?php echo $item->nif; ?>
</td>
<td>
<?php echo $item->fecha_nac; ?>
</td>
<td>
<?php echo $item->reserva; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
Upvotes: 1
Views: 1052
Reputation: 787
I guess you have already found the bug, but for everyone else, based on the provided code:
<form action="<?php echo JRoute::_('index.php?option=com_inscripciones&view=anuals$layout=default'); ?>" ...>
This line is wrong. Your view call is &view=anuals$layout=default.
Correct would be &view=anuals&layout=default
The only reason why you got that view error.
Please mark my answer as correct if that was you problem back in 2014.
Upvotes: 0
Reputation: 11
My query line in model looks like
$query->order($db1->getEscaped($this->getState('list.ordering', 'ordering')).' '.$db1->getEscaped($this->getState('list.direction', 'ASC')));
and populateState contains
$orderCol = JRequest::getCmd('filter_order', 'ordering');
$this->setState('list.ordering', $orderCol);
and the construct on the filter_fields contains
$this->_order[] = JRequest::getVar('filter_order', 'fieldName', 'POST', 'cmd');
$this->_order[] = JRequest::getVar('filter_order_Dir', 'asc', 'POST', 'word');
I had some trouble getting these working in some views in a component I made, just a lot of combinations of things that can be wrong, but you'll get there. I used this tutorial http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Introduction
Upvotes: 0