Yii Framework Forum: Yii2-Sortable-Input - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii2-Sortable-Input An extension allowing to drag drop lists and store sort order. Rate Topic: -----

#1 User is offline   Kartik V 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 639
  • Joined: 29-August 12

Posted 26 June 2014 - 01:47 PM

This is the forum for the yii2-sortable-input extension for Yii framework 2.0. This widget extends the yii2-sortable features by allowing you to drag drop lists and grids and store and save the sort order list..

Refer documentation and demos.
0

#2 User is offline   arsitek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 134
  • Joined: 10-October 08

Posted 20 May 2015 - 12:45 AM

Hi Kartik-v,

I had a problem when setting up this extension where the field value not changing while new item add to their column.

I attached an image to show my problem clrearly.

Posted Image

Here's my view
<?php
use yii\helpers\Html;
use kartik\sortinput\SortableInput;

use app\models\Menu;

/* @var $this yii\web\View */
$this->title = 'Sortable Input';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
    <h1><?= Html::encode($this->title) ?></h1>
</div>

<div class="row">
    <div class="col-sm-3">
        <h3>Left Column</h3>
    <?php 
        $leftmenus=Menu::find()
                ->where(['position' => 'left'])
                ->all();

        $litems = [];
        foreach ($leftmenus as $lmenu) {
            $litems[$lmenu->id] = [
                                'content' => $lmenu->name,
                                'options' => ['data' => ['id'=>$lmenu->id]],
                            ];
        }

        echo SortableInput::widget([
            'name'=>'left-column',
            'items' => $litems,            
            'hideInput' => false,
            'sortableOptions' => [
                'itemOptions'=>['class'=>'alert alert-info'],
                'connected'=>true,
            ],
            'options' => ['class'=>'form-control', 'readonly'=>true]
        ]);
     ?>
    </div> <!-- /.col-sm-3 -->

    <div class="col-sm-3">
        <h3>Center Column</h3>
    <?php 
        $centermenus=Menu::find()
                ->where(['position' => 'center'])
                ->all();

        $citems = [];
        foreach ($centermenus as $cmenu) {
            $citems[$cmenu->id] = [
                                'content' => $cmenu->name,
                                'options' => ['data' => ['id'=>$cmenu->id]],
                            ];
        }

        echo SortableInput::widget([
            'name'=>'center-column',
            'items' => $citems,            
            'hideInput' => false,
            'sortableOptions' => [
                'itemOptions'=>['class'=>'alert alert-success'],
                'connected'=>true,
            ],
            'options' => ['class'=>'form-control', 'readonly'=>true]
        ]);
     ?>
    </div> <!-- /.col-sm-3 -->

    <div class="col-sm-3">
        <h3>Right Column</h3>
    <?php 
        $rightmenus=Menu::find()
                ->where(['position' => 'right'])
                ->all();

        $ritems = [];
        foreach ($rightmenus as $rmenu) {
            $ritems[$rmenu->id] = [
                                'content' => $rmenu->name,
                                'options' => ['data' => ['id'=>$rmenu->id]],
                            ];
        }

        echo SortableInput::widget([
            'name'=>'right-column',
            'items' => $ritems,            
            'hideInput' => false,
            'sortableOptions' => [
                'itemOptions'=>['class'=>'alert alert-danger'],
                'connected'=>true,
            ],
            'options' => ['class'=>'form-control', 'readonly'=>true]
        ]);

     ?>
    </div> <!-- /.col-sm-3 -->

</div> <!-- /.row -->


and my database if need it
--
-- Table structure for table `menu`
--

CREATE TABLE IF NOT EXISTS `menu` (
  `id` int(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `position` varchar(255) DEFAULT NULL,
  `ordering` int(11) DEFAULT NULL
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `menu`
--

INSERT INTO `menu` (`id`, `name`, `position`, `ordering`) VALUES
(1, 'Menu 1', 'left', 1),
(2, 'Menu 2', 'left', 2),
(3, 'Menu 3', 'left', 3),
(4, 'Menu 4', 'left', 4),
(5, 'Menu 5', 'left', 5),
(6, 'Menu 6', 'center', 6),
(7, 'Menu 7', 'center', 7),
(8, 'Menu 8', 'center', 8),
(9, 'Menu 9', 'center', 9),
(10, 'Menu 10', 'center', 10),
(11, 'Menu 11', 'right', 11),
(12, 'Menu 12', 'right', 12),
(13, 'Menu 13', 'right', 13),
(14, 'Menu 14', 'right', 14),
(15, 'Menu 15', 'right', 15);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `menu`
--
ALTER TABLE `menu`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `menu`
--
ALTER TABLE `menu`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=16;



Thanks for help and a great extension.

Attached File(s)


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users