可排序的列Joomla

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>

dousui8263
dousui8263 谢谢你的回复,但不幸的是我的问题仍然存在。
6 年多之前 回复
dongzhiyong8577
dongzhiyong8577 尝试在$query->order中删除nombre和ASC($db->escape($this->getState('list.ordering','nombre'))。''。$db->escape($this->getState('list.direction','ASC')));
6 年多之前 回复
duanchao5258
duanchao5258 请帮忙!
6 年多之前 回复
duan0414
duan0414 好。添加了相关的源代码。谢谢。
6 年多之前 回复
douyun8901
douyun8901 请提供相关的源代码,如果没有,我们只能猜出问题是什么。
6 年多之前 回复

2个回答



我在模型中的查询行看起来像</ p>

  $ query-&gt; order(  $ db1-&gt; getEscaped($ this-&gt; getState('list.ordering','ordering'))。''。$ db1-&gt; getEscaped($ this-&gt; getState('list.direction','  ASC')));

</ code> </ pre>

并且populateState包含</ p>

  $ orderCol = JRequest :: getCmd('filter_order','ordering')  ; 
$ this-&gt; setState('list.ordering',$ orderCol);
</ code> </ pre>

filter_fields上的构造包含</ p>

  $ this-&gt; _order [] = JRequest :: getVar('filter_order','fieldName','POST','cmd'); 
$ this-&gt; _order [] = JRequest :: getVar('filter_order_Dir','asc','POST','word');
</ code> </ pre>

我在使用某些视图时遇到了一些问题 我制作的一个组件,只是很多可能出错的组合,但你会到达那里。 我使用了这个教程
http://docs.joomla.org/J2.5:Developing_a_MVC_Component /简介 </ p>
</ 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 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



我猜你已经找到了这个bug,但对于其他人来说,基于提供的代码:</ p>

 &lt; form action =“&lt;?php echo JRoute :: _('index.php?option = com_inscripciones&amp; view = anuals $ layout = default');?&gt;”  ...&gt; 
</ code> </ pre>

此行错误。 您的查看通话是&amp; view = anuals $ layout = default </ em>。</ p>

正确的是&amp; view = anuals&amp; layout = default </ em > </ p>

您获得该视图错误的唯一原因。</ p>

如果您在2014年遇到问题,请将我的答案标记为正确。</ p>
</ div>

展开原文

原文

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.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐