Lattice Grid Buy a licence

demo D106

Advisory locking

A peer holding a cell, and what happens if you edit it anyway

presence lock

Building…
Loading a live grid…

The configuration

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.13.0/lattice-grid.min.css">
<script src="https://cdn.jsdelivr.net/npm/@toclocoinc/lattice-grid@1.13.0/lattice-grid.min.js"></script>

<div id="grid" style="height: 540px"></div>

<script>
  const grid = LatticeGrid.createGrid(document.getElementById('grid'), {
    rowKey: 'id',
    selection: 'multiple',
    edit: true,
    columns: [
      { field: 'circuit', title: 'Circuit', layout: { width: 200, pin: 'start' } },
      { field: 'region', title: 'Region', edit: true },
      { field: 'status', title: 'Status', filter: { type: 'set' }, edit: true },
      { field: 'bandwidth', title: 'Bandwidth', type: 'number', filter: { type: 'number' }, edit: true },
      { field: 'charge', title: 'Monthly charge', type: 'number',
        format: { style: 'currency', currency: 'GBP' }, filter: { type: 'number' }, edit: true },
    ],
    presence: {
      // Your transport. When a peer announces an editing claim, the grid shows
      // the cell as held and names the holder.
      provider: {
        subscribe(onMessage) {
          // Deliver peer states, including editing claims, then return an unsubscribe.
          return () => {};
        },
        publish(state) {
          // Send the local cursor, selection and edit claim to the other clients.
        },
      },
      me: { id: 'you', name: 'You' },
      // Advisory, and only advisory. It reduces collisions rather than removing
      // them: the authoritative resolution is a conditional write in edit.commit,
      // which is the server's job and not the grid's.
      lock: true,
    },
    rows,  // an array of objects, one per circuit
  });
</script>

Advisory locking to stop two editors overwriting the same cell

Advisory locking marks a cell as held by whichever collaborator is currently editing it, so a second person working the same JavaScript data grid sees the hold before they type over it rather than after. It belongs alongside collaborative presence: presence shows where peers are looking, and the lock is the stronger signal that says a specific cell is mid-edit and should be treated as claimed. Lattice Grid exposes this through the presence lock mechanism, which a host wires to its own realtime channel so the grid only needs to render the lock state and enforce it locally; the lock is advisory rather than a hard write barrier, so a peer can still attempt an edit against a held cell, and the grid then shows whose hold it is and what happens to that edit rather than blocking the keystroke outright. Locks are scoped per cell, not per row or column, which keeps two people working the same record on different fields from ever contending. Rendering a lock indicator reuses the existing cell overlay layer, so marking and clearing a hold across a scrolled viewport of thousands of rows costs a lookup against the currently rendered cells rather than a pass over the full row set, and the indicator clears the instant the owning session releases or disconnects.

What is advisory locking in a collaborative data grid?

Advisory locking flags a cell as held by another editor without physically preventing a second person from typing into it. Lattice Grid renders the holder’s identity on the cell through presence lock and reports the conflict if someone edits it anyway, leaving the host application to decide whether that edit proceeds, queues, or is rejected upstream.