Sha256: c6ebd081777c8d1d37a55e6886da1515bd611088ebc49372165f48c32666c148
Contents?: true
Size: 903 Bytes
Versions: 2
Compression:
Stored size: 903 Bytes
Contents
import {Controller} from "stimulus" import Sortable from "sortablejs"; import Rails from "@rails/ujs"; export default class extends Controller { static get values() { return {url: String} } static get targets() { return ["table", "body"] } connect() { new Sortable(this.bodyTarget, { handle: '.table-drag-sort-handle', onEnd: (event) => { Rails.ajax({ url: this.urlValue, type: "PATCH", data: this.getIdsDataString(), }); } }) } getIdsDataString() { const table = this.tableTarget let data = "" const handles = [...table.querySelectorAll(".table-drag-sort-handle")] handles.map(handle => { data += `ids[]=${handle.dataset.id}&` }) return data } }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
headmin-0.1.2 | src/js/headmin/controllers/table_controller.js |
headmin-0.1.1 | src/js/headmin/controllers/table_controller.js |