dqknycyt92288 2014-06-26 13:12
浏览 76

可排序的列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>

  • 写回答

2条回答 默认 最新

  • douhuiqi3855 2014-07-15 17:59
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3