This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Scott
Scott

Just a quick proof of concept that allows a backend list to be re-ordered via drag and drop. If anyone has suggestions for better ways to achieve this kind of functionality, I would love to hear it!

https://github.com/scottbedard/draganddrop

daftspunky
daftspunky

The RainLab.Forum plugin supports reordering Channels. This looks good though :-)

jakobf
jakobf

Hi,

I needed ordering as well and found a "Sortable" trait in the October core.

You just need to add an integer to the corresponding model table with the name sort_order (can be changed I think).

Then add the trait to the model using

    use \October\Rain\Database\Traits\Sortable;

and sticking to the array format expected by the trait (I think its one array with the ids and one array with the ordering).

This way you get around writing the model stuff which is already there using the trait.

In my case I added a sort-action to the backend controller and realized the sorting via jqueryUI-sortable and ajax using an additional onSort-controller-action to handle the saving using the

$model->setSortableOrder($ids,$ordering)

from the trait and a nice blinking css to signal a successful save. But integrating the sorting in the default scaffolded indexing in the backend controller should be part of the core I think.

So all in all I think it's very close to your solution besides the usage of the trait.

Regards Jakob

Last updated

planetadeleste
planetadeleste

Great post. Small, simple and all helping. I use the @Scott method with @jakobf tip. Only one small change.

/*
 * Reorder the row positions
 */
public function index_onUpdatePosition()
{
    if (($reorderIds = post('checked')) && is_array($reorderIds) && count($reorderIds)) {
        $model = new Project;
        $model->setSortableOrder($reorderIds, array_keys($reorderIds));
        Flash::success('Successfully re-ordered records.');
    }
    return $this->listRefresh();
}

Thanks all for share

Scott
Scott

@planetadeleste, that attempt of mine is pretty old, I don't recommend it. Also, this is a planned feature for OctoberCMS, I would just wait until the official way to do this is complete. https://github.com/octobercms/october/issues/943

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.