Skip to content

softDeletes ​

Adds a Show deleted toggle to the toolbar. While it is on, server requests carry _deleted=1 and deleted rows are shown muted; while it is off, they are hidden.

js
import { Datagrid, column, serverSide, yajra, softDeletes } from "@akinozgen17/datagrids";
import { statusLabels, statusTones } from "./data.js";

new Datagrid("#mod-soft-deletes", {
  label: "Field agents (soft deletes)",
  columns: [
    { key: "ref", title: "Ref" },
    { key: "name", title: "Name" },
    { key: "unit", title: "Unit" },
    column.badge("status", { title: "Status", labels: statusLabels, tones: statusTones }),
    column.date("deleted_at", { title: "Deleted", time: true }),
  ],
  sort: [["deleted_at", "desc"]],
  pageSize: 10,
  use: [
    serverSide({ url: "/api/agents", protocol: yajra(), csrf: true }),
    softDeletes(),
  ],
});
html
<table id="mod-soft-deletes"></table>

When to use it ​

Use it on lists backed by soft-deleted records (Laravel's SoftDeletes) where admins sometimes need to see — and restore — what was deleted. Skip it when deleted records have their own page.

Usage ​

js
import { Datagrid, serverSide, yajra, softDeletes } from "@akinozgen17/datagrids";

new Datagrid("#agents", {
  label: "Field agents",
  columns,
  use: [serverSide({ url: "/api/agents", protocol: yajra(), csrf: true }), softDeletes()],
});

The controller decides what _deleted=1 means:

php
$query = Agent::query()->when($request->boolean('_deleted'), fn ($q) => $q->withTrashed());

Start switched on when the page was opened with ?deleted=1, and only for admins:

js
softDeletes({
  initial: new URLSearchParams(location.search).has("deleted"),
  can: user.isAdmin,
});

On a client grid (array, DOM, fetchAll) the toggle filters in the browser: deleted rows are hidden until it is switched on.

Options ​

OptionTypeDefaultDescription
paramstring"_deleted"Request parameter sent while on (server grids). On client grids, the filter key.
valueunknown1Its value.
fieldstringdeleted, then deleted_atRow field (dotted path allowed) that marks a deleted row; any truthy value counts.
labelstring"Show deleted"Button text and accessible name.
initialbooleanfalseStart switched on.
messages{ label }locale (en / tr)Translations.
slot"start" | "end""end"Toolbar slot.
ordernumber-10Position inside the slot (before the record count).
canbooleantruePermission flag: false → no button, no parameter.

API added to the grid ​

Available as grid.softDeletes (typed: grid.module(softDeletes)).

MemberReturnsDescription
active()booleantrue while deleted rows are shown.
toggle(on?)voidSwitches (or sets) the mode and reloads (server) or re-filters (client).

Events ​

None of its own. Toggling reloads a server grid (beforeLoad, load).

Pipelines it plugs into ​

  • Request middleware: adds param=value while on.
  • Filters (client grids): a row predicate under the param key; functions never reach the wire.
  • Row mutator: sets data-tone="muted" on deleted rows.
  • Toolbar: end slot, order -10.

Works with ​

  • Enhances actions: show a "Restore" action only on deleted rows with can: (row) => !!row.deleted_at.
  • With filterPanel: independent; both add their parameters.
  • The toggle is not saved by stateSave or written by urlSync; use initial to restore it.

Accessibility ​

The toggle is a real <button aria-pressed> with a permanent checkbox indicator, so its state is visible without hovering and announced as "Show deleted, toggle button, pressed". The muted row tone is visual only; add a visible "Deleted" column or badge (as in the demo) so the state does not rely on color alone.

Replaces in DataTables ​

No direct equivalent in 1.10, 2.x or 3.x. It replaces a hand-made toggle that set a flag read in ajax.data, called table.ajax.reload(), and marked rows in createdRow.

Gotchas ​

  • Deleted rows are not muted. The rows have no deleted / deleted_at field; set field.
  • The toggle changes nothing on a server grid. The endpoint must read _deleted (or your param).
  • On a client grid deleted rows are gone at first. By design; pass initial: true to show them from the start.

Released under the MIT License.