CxJS

PropertySelection

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

PropertySelection tracks selection state using a boolean property on each record. When an item is selected, its selected property (or custom field) is set to true.

When to Use

  • Checkbox-based selection where each row has a checkbox
  • When selection state should be saved with the data
  • When you need to easily filter or count selected items
  • Scatter graphs and other charts with selectable points

Example

<div controller={PageController} class="flex flex-col gap-4">
  <Grid
    records={m.items}
    selection={{
      type: PropertySelection,
      multiple: true,
    }}
    columns={[
      {
        items: <Checkbox value={m.$record.selected} />,
        align: "center",
        width: 30,
      },
      { header: "Name", field: "name" },
    ]}
  />
  <div class="p-3 bg-muted rounded text-sm">
    <strong>Store content</strong>
    <pre
      class="mt-2"
      text={(data: any) => JSON.stringify({ items: data.items }, null, 2)}
    />
  </div>
</div>
Name
Apple
Banana
Cherry
Date
Store content
{
  "items": [
    {
      "id": 1,
      "name": "Apple",
      "selected": false
    },
    {
      "id": 2,
      "name": "Banana",
      "selected": true
    },
    {
      "id": 3,
      "name": "Cherry",
      "selected": false
    },
    {
      "id": 4,
      "name": "Date",
      "selected": false
    }
  ]
}

Configuration

PropertyTypeDefaultDescription
selectedFieldstring"selected"Field name on each record that stores the selection state
multiplebooleanfalseEnable multiple selection
togglebooleanfalseEnable toggle mode (clicking selected item deselects it)