UNPKG

@flavorly/vanilla-components-inertia

Version:

🤌 Inertia integration for @flavorly/vanilla-components

40 lines (39 loc) • 1.26 kB
import { router } from "@inertiajs/vue3"; export default function useInertiaDatatable(configuration, options = { actionsCallback: true }) { if (options.actionsCallback && configuration.actions?.length > 0) { configuration.actions = configuration.actions.map((action) => { if (action.after?.inertia) { action.after.callback = (action2, data, datatable) => { const inertia = action2.after?.inertia; if (inertia && inertia.reload) { router.reload({ ...inertia.options, data: { ...inertia.options?.data || {}, datatable: { [datatable.name]: data } } }); } if (inertia && !inertia.reload && action2.after?.inertia?.url) { router.visit(inertia.url, { ...inertia.options, data: { ...inertia.options?.data || {}, datatable: { [datatable.name]: data } } // data: inertia.options.data ? { ...inertia.options.data, ...data } : data, }); } }; } return action; }); } return configuration; }