CxJS

SimpleSelection

import { SimpleSelection } from 'cx/ui'; Copied

SimpleSelection is the most basic selection model. It stores the entire selected object in the bound variable. Only single selection is supported.

When to Use

  • Simple single-select scenarios
  • When you need immediate access to the full selected object
  • Quick prototyping or simple lists

Note that selection is lost if the selected object changes in the data source, since the reference will no longer match. For more robust selection, consider KeySelection.

Example

<div controller={PageController} class="flex flex-col gap-4">
  <List
    records={m.items}
    selection={{
      type: SimpleSelection,
      bind: m.selection,
    }}
  >
    <div text={m.$record.name} />
  </List>
  <div class="p-3 bg-muted rounded text-sm">
    <strong>Store content</strong>
    <pre
      class="mt-2"
      text={(data) => JSON.stringify({ selection: data.selection }, null, 2)}
    />
  </div>
</div>
  • Apple
  • Banana
  • Cherry
  • Date
Store content
{}

Configuration

PropertyTypeDefaultDescription
bindProp<any>Binding for the selected object
togglebooleanfalseEnable toggle mode (clicking selected item deselects it)