J3.0 drag and drip sorting.

557 views
Skip to first unread message

rgjoyce

unread,
Mar 30, 2013, 9:44:07 PM3/30/13
to joomla-de...@googlegroups.com
Can someone please tell me what I need to do to get the drag and drop sorting functioning and saving?
Is there some special library that I have to include?

rgjoyce

unread,
Mar 30, 2013, 9:44:52 PM3/30/13
to joomla-de...@googlegroups.com
Sorry, Drag and Drop :)

Tim Plummer

unread,
Apr 1, 2013, 7:39:44 PM4/1/13
to joomla-de...@googlegroups.com
For drag & drop ordering, first you need to make sure you have an ordering field in your table.
Then there is some code you need to add to your view, if you take a look at /administrator/components/com_weblinks/views/weblinks/tmpl/default.php, you will see the following code. Obviously replace weblinks with your component name. And weblinkList should match the id of the table in the view.

$canOrder    = $user->authorise('core.edit.state', 'com_weblinks.category');
$saveOrder    = $listOrder == 'a.ordering';
if ($saveOrder)
{
    $saveOrderingUrl = 'index.php?option=com_weblinks&task=weblinks.saveOrderAjax&tmpl=component';
    JHtml::_('sortablelist.sortable', 'weblinkList', 'adminForm', strtolower($listDirn), $saveOrderingUrl);
}
$sortFields = $this->getSortFields();
?>
<script type="text/javascript">
    Joomla.orderTable = function()
    {
        table = document.getElementById("sortTable");
        direction = document.getElementById("directionTable");
        order = table.options[table.selectedIndex].value;
        if (order != '<?php echo $listOrder; ?>')
        {
            dirn = 'asc';
        }
        else
        {
            dirn = direction.options[direction.selectedIndex].value;
        }
        Joomla.tableOrdering(order, dirn, '');
    }
</script>


You then need the ordering column heading in the view

                    <th width="1%" class="nowrap center hidden-phone">
                        <?php echo JHtml::_('grid.sort', '<i class="icon-menu-2"></i>', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING'); ?>
                    </th>


and the ordering row of the column

                    <td class="order nowrap center hidden-phone">
                    <?php if ($canChange) :
                        $disableClassName = '';
                        $disabledLabel      = '';
                        if (!$saveOrder) :
                            $disabledLabel    = JText::_('JORDERINGDISABLED');
                            $disableClassName = 'inactive tip-top';
                        endif; ?>
                        <span class="sortable-handler hasTooltip <?php echo $disableClassName?>" title="<?php echo $disabledLabel?>">
                            <i class="icon-menu"></i>
                        </span>
                        <input type="text" style="display:none" name="order[]" size="5" value="<?php echo $item->ordering;?>" class="width-20 text-area-order " />
                    <?php else : ?>
                        <span class="sortable-handler inactive" >
                            <i class="icon-menu"></i>
                        </span>
                    <?php endif; ?>
                    </td>


Since this field calls getSortFields, you'll need to define this in your view.html.php (refer to /administrator/components/com_weblinks/views/weblinks/view.html.php)

    protected function getSortFields()
    {
        return array(
            'a.ordering' => JText::_('JGRID_HEADING_ORDERING'),
            'a.state' => JText::_('JSTATUS'),
            'a.title' => JText::_('JGLOBAL_TITLE'),
            'a.access' => JText::_('JGRID_HEADING_ACCESS'),
            'a.hits' => JText::_('JGLOBAL_HITS'),
            'a.language' => JText::_('JGRID_HEADING_LANGUAGE'),
            'a.id' => JText::_('JGRID_HEADING_ID')
        );
    }


And in your controller, you'll need to add the saveOrderAjax function (refer to /administrator/components/com_weblinks/controllers/weblinks.php).

    public function saveOrderAjax()
    {
        // Get the input
        $input = JFactory::getApplication()->input;
        $pks = $input->post->get('cid', array(), 'array');
        $order = $input->post->get('order', array(), 'array');

        // Sanitize the input
        JArrayHelper::toInteger($pks);
        JArrayHelper::toInteger($order);

        // Get the model
        $model = $this->getModel();

        // Save the ordering
        $return = $model->saveorder($pks, $order);

        if ($return)
        {
            echo "1";
        }

        // Close the application
        JFactory::getApplication()->close();
    }


It seems a bit complex at first, but a lot of this is just copy and paste. Good luck.

regards

Tim Plummer


On Sun, Mar 31, 2013 at 12:44 PM, rgjoyce <r...@osdcs.com> wrote:
Sorry, Drag and Drop :)

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Rob Joyce

unread,
Apr 3, 2013, 11:08:17 PM4/3/13
to joomla-de...@googlegroups.com
Hi Tim,
  it's a good start, but are you sure ther eis nothing missing here?
I've done it as you've said but it doesn't seem to work.
 
Rob

Mary Kalinosky

unread,
Dec 7, 2017, 1:00:27 PM12/7/17
to Joomla! General Development
Thanks for the detailed instructions, Tim. My problem here seems to be that the controller for my list view uses a "list model," meaning the model I wrote for the list of items, which extends JModelList and not JModelAdmin. JModelAdmin is the model that contains the saveorder() function, which is called from the controller's saveOrderAjax() function. JModelList does not have this function. I could write the saveorder() function for my list model, but it seems like the Joomla framework should allow for this ordering feature without a lot of hacking. Honestly, it doesn't make sense that JModelList doesn't implement saveorder(). Perhaps I should just go ahead and implement the saveorder() function in my JModelList class (?).

Thanks in advance for any help.

Mary
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages