简体   繁体   English

可排序的列Joomla

[英]Sortable columns Joomla

I'm developing a MVC component for Joomla! 我正在为Joomla开发MVC组件! 2.5 and I want to add some sortable columns in my backend. 2.5,我想在后端添加一些可排序的列。 For this goal I've tried to do the next: 为了这个目标,我尝试了下一个:

http://docs.joomla.org/Adding_sortable_columns_to_a_table_in_a_component 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 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 如何在带有箭头的ASC和DESC的Joomla组件(表)中添加可排序的列

&

Joomla 2.5 -Adding sortable columns to a table in a component Joomla 2.5-将可排序的列添加到组件中的表

But my problem persits. 但是我的问题困扰着。 What can I do?? 我能做什么?? Thank you. 谢谢。

MY RELEVANT SOURCE CODE IS THE NEXT: 我的相关源代码是下一个:

com_inscripciones/admin/models/anuals.php com_inscripciones /管理/模型/ 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 com_inscripciones /管理/视图/ 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 com_inscripciones /管理/视图/ 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>

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 和populateState包含

$orderCol   = JRequest::getCmd('filter_order', 'ordering');
            $this->setState('list.ordering', $orderCol);

and the construct on the filter_fields contains 并且filter_fields上的构造包含

$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 我使用了本教程http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Introduction

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 . 您的视图调用是&view = anuals $ layout = default

Correct would be &view=anuals&layout=default 正确的是&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. 如果您在2014年遇到问题,请将我的回答标记为正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM