# Cell Editor Typing Modes in a Blazor Server Grid

URL: https://flexcoreui.com/demo/grid/typing-modes  
Section: Data Grid  
Controls: GridControl, GridColumn, TextBoxControl  
Keywords: Blazor Server latency, input lag, client-buffered editing, cell editor

Choose where typing in a Blazor grid cell goes: to the server with each keystroke, or kept in the browser until the cell commits.

## Documentation

### Modes

| Name | Description |
|---|---|
| ServerBacked | The ordinary Blazor event path. The input binds oninput, so every keystroke is a round trip: the server runs InputValueChanged with the text so far, and ValueChanged on the native change event (Enter or blur) unless UpdateOnInput is set. The grid's cell editor also sets TypingKeysStayLocal, so a typing key costs one message (its input event) rather than two; Enter and blur reach the server as keydown and blur events and commit the cell. |
| ClientBuffered | The browser owns the text. The input renders data-fx-cb-pending so typing keys stay local from the first paint, then textbox-control.js attaches a listener that stops the input, change, blur and typing keydown events from reaching Blazor. It sends the whole value once, through CommitClientBufferedTypingAsync, on Enter, Tab, Up, Down, Page Up, Page Down, Ctrl+Home, Ctrl+End, an arrow at either end of the text, or blur; that call sets Value, runs InputValueChanged and ValueChanged, then forwards the key to OnKeyDown or raises OnBlur (Escape is forwarded without storing). The grid commits the cell from that forwarded key or blur, and reads the browser text itself before a click on another cell commits. |

### Grid

| Name | Type | Default | Description |
|---|---|---|---|
| TextEditorTypingBehavior | TextBoxTypingBehavior | TextBoxTypingBehavior.ServerBacked | Passed as TypingBehavior to the TextBoxControl the grid builds for a text or number cell in batch edit; the other cell editors do not read it. An editor that fans out to several selected rows or cells is forced to ServerBacked. The grid also uses the resolved value to decide whether to read the browser text before a click elsewhere commits, whether Tab is left to the grid host, and whether to guard a committed Enter from re-opening the editor. |
| UseClientBufferedTextEditing | bool? | null | true or false overrides TextEditorTypingBehavior for a host that switches the transport with a flag; null follows it. Every read site goes through this override. |

### Grid methods

| Name | Type | Description |
|---|---|---|
| GetTextEditingDiagnosticsSnapshot() | GridTextEditingDiagnosticsSnapshot | This grid's counters of what its text editors sent to the server, for comparing the two modes. |
| ResetTextEditingDiagnostics() | void | Zeroes those counters. |

### Snapshot

| Name | Type | Description |
|---|---|---|
| ServerInputCallbacks | long | Input events a ServerBacked editor sent, one per keystroke; also counted for a ClientBuffered editor whose browser listener never attached and fell back to per-character events. |
| ServerValueChangedCallbacks | long | ValueChanged calls from a ServerBacked editor: its native change event on Enter or blur. |
| ServerKeyDownCallbacks | long | Keydown events a ServerBacked editor sent (Enter, Tab, arrows and other non-typing keys; typing keys stay local), plus any typing key that reached a ClientBuffered editor's OnKeyDown, which only happens while its listener is not attached. |
| ServerBlurCallbacks | long | Blur events a ServerBacked editor sent. |
| ClientBufferedCommitCallbacks | long | OnKeyDown and OnBlur calls from an attached ClientBuffered editor: one per forwarded key or blur, each carrying the completed value. |
| TotalServerCallbacks | long | The four server counters added together. Getter only. |

### Text box

| Name | Type | Default | Description |
|---|---|---|---|
| TypingBehavior | TextBoxTypingBehavior | TextBoxTypingBehavior.ServerBacked | Which of the two paths this box uses. ClientBuffered always renders the raw input (never the InputText form fast path), keeps a browser-owned value whatever Uncontrolled says, and loads textbox-control.js after the first render to attach its listener. A box inside a cell host (the cascading ICellEditorHost of a hosted cell template) is ClientBuffered regardless of this value. |
| UpdateOnInput | bool | false | ServerBacked: ValueChanged runs on every input event instead of on the native change event, and the form fast path is skipped. It has no effect once a ClientBuffered listener is attached, because input events no longer reach the server. |
| InputValueChanged | Action<string?>? | null | Runs before ValueChanged with the same text: on every input event in ServerBacked, and with the committed value on each ClientBuffered commit. An Action rather than an EventCallback, so it does not re-render the parent by itself. The grid feeds its edit buffer from it. |
| Uncontrolled | bool | true | The input keeps its own text and a parent re-render never writes an older Value back over it; a different Value set from outside re-seeds the draft. false is the controlled input whose rendered value tracks Value on every render. A ClientBuffered box is browser-owned either way. |
| ReseedOnOutsideChange | bool | true | With Uncontrolled and ServerBacked, a Value change from the parent re-seeds the draft; false leaves the DOM text alone, for a host that pushes server-side values itself (the grid's editor sets it false). Not read for ClientBuffered or hosted boxes. |
| TypingKeysStayLocal | bool | false | ServerBacked only: printable keys, Backspace and Delete are never dispatched as keydown events (their input events still are), which is how the grid's editor keeps a keystroke to one message. Ignored when ClientBuffered, whose listener already owns those keys. |
| KeepNativeTab | bool | false | ClientBuffered with an OnKeyDown host: Tab commits the draft and reaches the host once, but its default is not prevented, so the browser moves focus itself. Grid cell editors leave it false and let the grid move the active cell. |
| MaxLength | int? | null | Rendered as the maxlength attribute; a ClientBuffered commit also clips the value it receives to this length. With an OnPasteTruncated delegate the browser reports a paste it had to shorten. |

### Text box events

| Name | Type | Description |
|---|---|---|
| ValueChanged | string? | ServerBacked: on the native change event, or on every input event with UpdateOnInput. ClientBuffered: on each commit, after InputValueChanged. |
| OnKeyDown | KeyboardEventArgs | ServerBacked: bound only when a delegate is set; then every keydown the browser dispatches reaches it. ClientBuffered: a delegate makes the listener own Enter, Tab, Escape, Up, Down, Page Up, Page Down and the edge arrows; each commits the draft first and is then forwarded here with the key and modifier flags, and typing keys never arrive. Without a delegate the box commits on blur (and on Enter inside a dialog with a default button). |
| OnBlur |  | After the value has been synchronized: through the native blur in ServerBacked, through the listener's Blur commit in ClientBuffered. Bound only when a delegate is set. |
| OnPasteTruncated | (int PastedLength, int MaxLength) | Raised from the browser when a paste was clipped by MaxLength, which happens before any input event. Attached only when MaxLength is set and a delegate exists; the grid maps it to CellValueTruncated. |

### Text box methods

| Name | Type | Description |
|---|---|---|
| FlushClientBufferedValueAsync() | Task | Reads the browser's current text and publishes it through InputValueChanged and ValueChanged without waiting for a commit key or blur, for a form that confirms with a button. Returns at once for a ServerBacked box. |
| FlushClientBufferedValueAsync(bool requireCurrentValue) | Task | The same; with true a failed read throws instead of silently keeping the older value. |
| CommitClientBufferedTypingAsync(string? value, string key, bool shiftKey, bool ctrlKey, bool altKey, bool metaKey) | Task | The JSInvokable entry the listener in textbox-control.js calls with the input's value and the key that ended the typing (or Blur, or Sync for a value-only flush). It stores the value, runs InputValueChanged and ValueChanged, then forwards the key to OnKeyDown or raises OnBlur; Escape is forwarded without storing. Page code does not call it. |

## Examples

### Transport

```razor
@using Fx.ControlKit
@using Fx.ControlKit.Grid

<GridControl TValue="AgentRow"
             DataSource="@_rows"
             Height="360px"
             AllowSelection="true"
             AllowSorting="true"
             TextEditorTypingBehavior="@(_clientBuffered ? TextBoxTypingBehavior.ClientBuffered : TextBoxTypingBehavior.ServerBacked)"
             EditSettingsRef="@_editSettings"
             EventsRef="@_events"
             CssClass="fx-grid-compact">
    <GridColumnsBase>
        <GridColumn Field="@nameof(AgentRow.ID)" HeaderText="Agent ID" Width="85px" AllowEditing="false" />
        <GridColumn Field="@nameof(AgentRow.FullName)" HeaderText="Full Name" Width="200px" AllowEditing="true" />
        <GridColumn Field="@nameof(AgentRow.Email)" HeaderText="Email Address" Width="220px" AllowEditing="true" />
        <GridColumn Field="@nameof(AgentRow.Phone)" HeaderText="Direct Phone" Width="130px" AllowEditing="true" />
        <GridColumn Field="@nameof(AgentRow.Desk)" HeaderText="Desk" Width="130px" AllowEditing="true" />
        <GridColumn Field="@nameof(AgentRow.TeamLead)" HeaderText="Team Lead" Width="90px" Type="ColumnType.Boolean" TextAlign="TextAlign.Center" AllowEditing="true" />
        <GridColumn Field="@nameof(AgentRow.DiscountLimit)" HeaderText="Discount Limit" Width="130px" Type="ColumnType.Number" TextAlign="TextAlign.Right" AllowEditing="true" Format="$#,##0" />
    </GridColumnsBase>
</GridControl>
<p class="result">@(_clientBuffered ? "ClientBuffered" : "ServerBacked") · @_saveCount @(_saveCount == 1 ? "cell" : "cells") saved@(_last is null ? "" : $"; last: {_last}")</p>
```

```csharp
public class AgentRow
{
    public string ID { get; set; } = string.Empty;
    public string FullName { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public string Phone { get; set; } = string.Empty;
    public string Desk { get; set; } = string.Empty;
    public bool TeamLead { get; set; }
    public decimal DiscountLimit { get; set; }
}

private readonly SelectionItem[] _transports = { new("server", "ServerBacked"), new("client", "ClientBuffered") };

private List<AgentRow> _rows = [];

private bool _clientBuffered = true;

private int _saveCount;

private string? _last;

private readonly EditSettings _editSettings = new()
{
    AllowEditing = true,
    Mode = EditMode.Batch
};

private readonly GridControlEvents<AgentRow> _events = new();

protected override void OnInitialized()
{
    _events.OnCellSave = EventCallback.Factory.Create<CellSaveArgs<AgentRow>>(this, args =>
    {
        _saveCount++;
        _last = $"{args.ColumnName} = {args.Value} on {args.Data.ID}";
    });

    _rows =
    [
        new AgentRow { ID = "AG-01", FullName = "Saffron Kettleby", Email = "skettleby@razorsharp-getaways.example", Phone = "(512) 555-0114", Desk = "Leisure desk", TeamLead = true, DiscountLimit = 1000m },
        new AgentRow { ID = "AG-02", FullName = "Rupert Inglenook", Email = "ringlenook@razorsharp-getaways.example", Phone = "(512) 555-0157", Desk = "Adventure desk", TeamLead = false, DiscountLimit = 250m },
        new AgentRow { ID = "AG-03", FullName = "Ottoline Figgis", Email = "ofiggis@razorsharp-getaways.example", Phone = "(512) 555-0208", Desk = "Cruise desk", TeamLead = false, DiscountLimit = 500m },
        new AgentRow { ID = "AG-04", FullName = "Cornelius Quill", Email = "cquill@razorsharp-getaways.example", Phone = "(512) 555-0263", Desk = "Touring desk", TeamLead = true, DiscountLimit = 1000m },
        new AgentRow { ID = "AG-05", FullName = "Wilhelmina Sprocket", Email = "wsprocket@razorsharp-getaways.example", Phone = "(512) 555-0329", Desk = "Luxury desk", TeamLead = false, DiscountLimit = 250m }
    ];
}

private void SetTransport(bool clientBuffered) => _clientBuffered = clientBuffered;
```

