Skip to main content
cngx-src documentation

CngxSortHeader

DirectivePrimaryv0.1.0WCAG AA

projects/common/data/sort/sort-header.directive.ts

Import#

import { CngxSortHeader } from '@cngx/common/data'

Description#

Molecule directive for sort-header elements.

Apply to any clickable header element. Consumer provides an explicit [cngxSortRef] binding - no ancestor injection, no hidden wiring.

In multi-sort mode, Shift+click adds this column to the sort stack. The priority() signal returns the 1-based position in the stack (0 when not active), useful for showing sort-order badges.

<div cngxSort [multiSort]="true" #sort="cngxSort">
  <button cngxSortHeader="name" [cngxSortRef]="sort" #h="cngxSortHeader">
    Name
    @if (h.isActive()) {
      {{ h.isAsc() ? '↑' : '↓' }}
      @if (sort.multiSort()) { <span>{{ h.priority() }}</span> }
    }
  </button>
</div>

https://cngxjs.github.io/cngx/examples/#/common/data/sort/basic https://cngxjs.github.io/cngx/examples/#/common/data/sort/multi-sort https://cngxjs.github.io/cngx/examples/#/common/data/sort/controlled https://cngxjs.github.io/cngx/examples/#/common/data/sort/aria-and-keyboard

Metadata#

Host#

Index#

Inputs#

cngxSortRef#CngxSort
input()Required

Explicit reference to the owning CngxSort.

field#string
input()Required

The field key this header cell represents.

default { alias: 'cngxSortHeader' }

Instance Properties#

isActive#unknown
Readonly

true when this column is part of the active sort (primary or secondary).

this.state.isActive
isAsc#unknown
Readonly

true when this column is active and sorted ascending.

this.state.isAsc
isDesc#unknown
Readonly

true when this column is active and sorted descending.

this.state.isDesc
priority#unknown
Readonly

1-based position of this column in the sort stack. Returns 0 when the column is not part of the active sort. Only meaningful when multiSort is enabled on the owning CngxSort.

this.state.priority

Methods#

handleSort#void
Protected
handleSort(event?: MouseEvent)
@paramevent?MouseEvent

HostBindings#

BindingExpression
[attr.aria-sort]ariaSort()
[class.cngx-sort-header--active]isActive()
[class.cngx-sort-header--asc]isAsc()
[class.cngx-sort-header--desc]isDesc()

HostListeners#

EventHandler
(click)click()