Counting Selections
Point any element at a selectable list with data-selection-target="id" and its [data-selection-count] slots stay live. Anything with a checked input.nds-check inside counts: no wiring, no table required
Swapping with the Records Counter
The counter's home in real layouts is the Toolbar above a table. Give one wrapper both targets and two views: the Pagination records line shows while browsing, and the selection line takes over when rows are selected, including via the table's select-all. Ship nds-selection-view with hidden so first paint is correct
|
|
Reference | Service |
|---|---|---|
|
|
REQ-1001 | Passport Renewal |
|
|
REQ-1002 | Driving Licence |
|
|
REQ-1003 | Commercial Registration |
|
|
REQ-1004 | Building Permit |
|
|
REQ-1005 | Health Card |
|
|
REQ-1006 | Work Visa |
Built-in Features
Activates when a data-selection-target element is on the page and recounts on every checkbox change, including a table's select-all.
Table rows, checkbox cards, and plain checkbox lists all count with the same rule: a checked input.nds-check inside the item. The card demo above has no JS of its own.
Wrappers holding nds-records-view and nds-selection-view children switch between them automatically while anything is selected.
Recount a list or every widget after dynamic DOM changes through the NDS.Selection API.
Usage Guidelines
Best Practices
- Use a selection counter wherever a bulk action exists (export, delete, assign): the number tells users what the action will affect before they commit
- The count is the bulk-action truth: it includes selections on other pages and on rows an active filter currently hides, matching exactly what Export's selected scope exports
- Place the counter in the Toolbar's info slot above the list, as the table demo shows: that is where users look for record counts
- Pair with the Pagination records counter through the two-view swap so one line serves both browsing and selecting
- Ship
nds-selection-viewwith thehiddenattribute: nothing is selected at first paint, and the view stays correct before scripts load - A single always-visible counter (like the card demo) needs no view classes: just the wrapper and a count slot
- Style selection-mode chrome (highlighted toolbar, action buttons appearing) off the wrapper's
data-state="has-selection"stamp rather than wiring your own listeners - Don't build per-page selection counts: if users need "selected on this page", rethink the flow, since bulk actions operate on the full selection
- Keep the sentence in your markup, in your language: the component only writes numbers, so plurals and Arabic phrasing are entirely yours
Data Attributes
| Attribute | Description |
|---|---|
data-selection-target="id" | Makes the element a selection counter for the list with that id. Its [data-selection-count] slots receive the count (with thousand separators), and it carries data-state="has-selection" while the count is above zero |
data-selection-count | Number slot inside the wrapper; any element works (<b> renders medium emphasis inside nds-bar-text) |
data-selection-total | Slot for the list's item count, so a standalone "x selected of y" works without Pagination. Paged lists can use data-paged-count instead (the filtered count) |
data-state="selected" | Alternative selected marker on an item, for content without checkboxes. Tables stamp it on rows automatically |
JavaScript API
The counter initializes automatically when a data-selection-target element exists on the page and reacts to checkbox changes on its own. Use the API after DOM changes checkboxes don't announce.