mkocansey/bladewind-sortable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mkocansey/bladewind-sortable

Composer 安装命令:

composer require mkocansey/bladewind-sortable

包简介

BladewindUI — Drag and drop sortable list component (powered by SortableJS)

README 文档

README

License Packagist Version

BladewindUI

Sortable

BladewindUI — Drag and drop sortable list component, powered by SortableJS.

Installation

composer require mkocansey/bladewind-sortable

Or install the full library:

composer require mkocansey/bladewind

Usage

<x-bladewind::sortable>
    <x-bladewind::sortable.item>Tomatoes</x-bladewind::sortable.item>
    <x-bladewind::sortable.item>Onions</x-bladewind::sortable.item>
    <x-bladewind::sortable.item>Garlic</x-bladewind::sortable.item>
</x-bladewind::sortable>

Attributes

Attribute Type Default Description
type simple|shared simple shared lists can exchange items with other lists in the same group.
group string null Group name used by shared lists to know which lists can swap items.
clone bool false Leave a copy behind when dragging an item into another (shared) list.
sortable bool true Enable or disable sorting of items within the list.
hasHandle bool false Drag items by a dedicated handle instead of the whole item surface.
handleIcon string bars-3 Heroicon name used for the drag handle when hasHandle is true.
filter string null Space/comma separated class names whose items cannot be dragged.
multidrag bool false Select (ctrl/cmd + click) and drag multiple items at once.
swap bool false Swap items on drop instead of shifting them. Not combinable with multidrag.
animation int 150 Reorder animation duration in milliseconds.
inputName string null Renders a hidden <input> with this name, kept in sync with the order as a JSON array. Submit it with your form.
onSorted string null Name of a JS function called after each reorder as (order, event). Useful for saving via AJAX.

The sortable.item component accepts a value attribute (rendered as data-id) — this is the identifier reported in the order array, e.g. your model id.

Saving the order

Submitting with a form. Give the list an inputName and each item a value. A hidden input is kept in sync with the order and submitted like any other field:

<form method="post" action="/tasks/reorder">
    @csrf
    <x-bladewind::sortable input-name="task_order" has-handle="true">
        @foreach($tasks as $task)
            <x-bladewind::sortable.item :value="$task->id">{{ $task->title }}</x-bladewind::sortable.item>
        @endforeach
    </x-bladewind::sortable>
    <x-bladewind::button can_submit="true" label="Save order"/>
</form>

On the server the field arrives as a JSON array of ids in their new order:

$order = json_decode($request->input('task_order')); // ["30", "10", "20"]

foreach ($order as $position => $id) {
    Task::where('id', $id)->update(['position' => $position]);
}

Saving with AJAX (no form submit). Point onSorted at a JS function that receives the order array:

<x-bladewind::sortable :on-sorted="'saveOrder'">
    @foreach($tasks as $task)
        <x-bladewind::sortable.item :value="$task->id">{{ $task->title }}</x-bladewind::sortable.item>
    @endforeach
</x-bladewind::sortable>

<script>
    function saveOrder(order, event) {
        fetch('/tasks/reorder', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
            },
            body: JSON.stringify({ task_order: order }),
        });
    }
</script>

Reading the order yourself. Each list is exposed as a JS variable named after its name, so you can call SortableJS methods directly — e.g. task_list.toArray() returns the current order at any time.

Sharing items between two lists

<x-bladewind::sortable type="shared" group="fruits">
    <x-bladewind::sortable.item>Apple</x-bladewind::sortable.item>
    <x-bladewind::sortable.item>Mango</x-bladewind::sortable.item>
</x-bladewind::sortable>

<x-bladewind::sortable type="shared" group="fruits">
    <x-bladewind::sortable.item>Banana</x-bladewind::sortable.item>
</x-bladewind::sortable>

Documentation

Full documentation, live demos, and all available attributes are at bladewindui.com.

License

MIT — see the LICENSE file.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固