php - Sortable columns Joomla -
i'm developing mvc component joomla! 2.5 , want add together sortable columns in backend. goal i've tried next:
http://docs.joomla.org/adding_sortable_columns_to_a_table_in_a_component
and got error "view not found [name, type, prefix]". in case have looking solution , find next:
http://forum.joomla.org/viewtopic.php?p=2638695
following indications have removed "action" of "form". in case column sortable, problem arises. if remove "action" of "form" "edit buttom" of toolbar not work.
i think there must solution because need working "edit buttom" , sortable column also. i've looking similar question here , i've applied next information:
how add together sortable columns in joomla component (table), both asc , desc arrow
&
joomla 2.5 -adding sortable columns table in component
but problem persits. can do?? give thanks you.
my relevant source code next:
com_inscripciones/admin/models/anuals.php
<?php // no direct access file defined('_jexec') or die('restricted access'); // import 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 build sql query load list data. * * @return string sql query */ protected function getlistquery() { // create new query object. $db = jfactory::getdbo(); $query = $db->getquery(true); // select fields $query->select('id,nombre,apellidos,nif,fecha_nac,reserva,validacion,clave'); // hello table $query->from('#__anual'); // add together list ordering clause. $query->order($db->escape($this->getstate('list.ordering', 'nombre')).' '.$db->escape($this->getstate('list.direction', 'asc'))); homecoming $query; } } ?>
com_inscripciones/admin/views/anuals/view.html.php
<?php // no direct access 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) { // info 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 errors. if (count($errors = $this->get('errors'))) { jerror::raiseerror(500, implode('<br />', $errors)); homecoming false; } // assign info view $this->items = $items; $this->pagination = $pagination; // set toolbar $this->addtoolbar(); // display template parent::display($tpl); } /** * setting 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 $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>
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 build on filter_fields contains
$this->_order[] = jrequest::getvar('filter_order', 'fieldname', 'post', 'cmd'); $this->_order[] = jrequest::getvar('filter_order_dir', 'asc', 'post', 'word');
i had problem getting these working in views in component made, lot of combinations of things can wrong, you'll there. used tutorial http://docs.joomla.org/j2.5:developing_a_mvc_component/introduction
php joomla joomla2.5
No comments:
Post a Comment