SlickEventData 10
An event object for passing data to event handlers and letting them control propagation.
<p>This is pretty much identical to how W3C and jQuery implement events.</p>
stopPropagation
stopPropagation()
Stops event from propagating up the DOM tree.
isPropagationStopped
isPropagationStopped()
Returns whether stopPropagation was called on this event object.
stopImmediatePropagation
stopImmediatePropagation()
Prevents the rest of the handlers from being executed.
isImmediatePropagationStopped
isImmediatePropagationStopped()
Returns whether stopImmediatePropagation was called on this event object.\
getNativeEvent
getNativeEvent()
preventDefault
preventDefault()
isDefaultPrevented
isDefaultPrevented()
addReturnValue
addReturnValue(value: any)
| Parameter | Type | Description |
|---|
value | any | |
getReturnValue
getReturnValue()
getArguments
getArguments()
SlickEvent 4
A simple publisher-subscriber implementation.
subscribe
subscribe(fn: Handler<ArgType>)
Adds an event handler to be called when the event is fired.
<p>Event handler will receive two arguments - an <code>EventData</code> and the <code>data</code>
object the event was fired with.<p>
| Parameter | Type | Description |
|---|
fn | Handler<ArgType> | - Event handler. |
unsubscribe
unsubscribe(fn?: Handler<ArgType>)
Removes an event handler added with <code>subscribe(fn)</code>.
| Parameter | Type | Description |
|---|
fn? | Handler<ArgType> | - Event handler to be removed. |
notify
notify(args: ArgType, evt?: SlickEventData<ArgType> | Event | MergeTypes<SlickEventData<ArgType>, Event> | null, scope?: any)
Fires an event notifying all subscribers.
| Parameter | Type | Description |
|---|
args | ArgType | Additional data object to be passed to all handlers. |
evt? | SlickEventData<ArgType> | Event | MergeTypes<SlickEventData<ArgType>, Event> | null | |
scope? | any | - The scope ("this") within which the handler will be executed.
If not specified, the scope will be set to the <code>Event</code> instance. |
setPubSubService
setPubSubService(pubSub: BasePubSub)
| Parameter | Type | Description |
|---|
pubSub | BasePubSub | |
SlickEditorLock 5
A locking helper to track the active edit controller and ensure that only a single controller
can be active at a time. This prevents a whole class of state and validation synchronization
issues. An edit controller (such as SlickGrid) can query if an active edit is in progress
and attempt a commit or cancel before proceeding.
isActive
isActive(editController?: EditController): boolean
Returns true if a specified edit controller is active (has the edit lock).
If the parameter is not specified, returns true if any edit controller is active.
| Parameter | Type | Description |
|---|
editController? | EditController | |
returns boolean
activate
activate(editController: EditController)
Sets the specified edit controller as the active edit controller (acquire edit lock).
If another edit controller is already active, and exception will be throw new Error(.
| Parameter | Type | Description |
|---|
editController | EditController | edit controller acquiring the lock |
deactivate
deactivate(editController: EditController)
Unsets the specified edit controller as the active edit controller (release edit lock).
If the specified edit controller is not the active one, an exception will be throw new Error(.
| Parameter | Type | Description |
|---|
editController | EditController | edit controller releasing the lock |
commitCurrentEdit
commitCurrentEdit(): boolean
Attempts to commit the current edit by calling "commitCurrentEdit" method on the active edit
controller and returns whether the commit attempt was successful (commit may fail due to validation
errors, etc.). Edit controller's "commitCurrentEdit" must return true if the commit has succeeded
and false otherwise. If no edit controller is active, returns true.
returns boolean
cancelCurrentEdit
cancelCurrentEdit(): boolean
Attempts to cancel the current edit by calling "cancelCurrentEdit" method on the active edit
controller and returns whether the edit was successfully cancelled. If no edit controller is
active, returns true.
returns boolean
BindingEventService 6
A simple binding event service to keep track of all JavaScript events with callback listeners,
it allows us to unbind event(s) and their listener(s) by calling a simple unbind method call.
Unbinding is a necessary step to make sure that all event listeners are removed to avoid memory leaks when destroing the grid
getBoundedEvents
getBoundedEvents()
destroy
destroy()
bind
bind(element: Element | Window | Document, eventName: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions, groupName?)
Bind an event listener to any element
| Parameter | Type | Description |
|---|
element | Element | Window | Document | |
eventName | string | |
listener | EventListenerOrEventListenerObject | |
options? | boolean | AddEventListenerOptions | |
groupName? | | |
unbind
unbind(element: Element | Window | Document, eventName: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions)
Unbind all will remove every every event handlers that were bounded earlier
| Parameter | Type | Description |
|---|
element | Element | Window | Document | |
eventName | string | |
listener | EventListenerOrEventListenerObject | |
options? | boolean | EventListenerOptions | |
unbindByEventName
unbindByEventName(element: Element | Window | Document, eventName: string)
| Parameter | Type | Description |
|---|
element | Element | Window | Document | |
eventName | string | |
unbindAll
unbindAll(groupName?: string | string[])
Unbind all event listeners that were bounded, optionally provide a group name to unbind all listeners assigned to that specific group only.
| Parameter | Type | Description |
|---|
groupName? | string | string[] | |
Utils 32
isFunction
isFunction(obj: any)
| Parameter | Type | Description |
|---|
obj | any | |
isPlainObject
isPlainObject(obj: any)
| Parameter | Type | Description |
|---|
obj | any | |
calculateAvailableSpace
calculateAvailableSpace(element: HTMLElement)
| Parameter | Type | Description |
|---|
element | HTMLElement | |
extend
extend(args: any[]): T
| Parameter | Type | Description |
|---|
args | any[] | |
returns T
createDomElement
createDomElement(tagName: T, elementOptions?: null | { [P in K]: InferDOMType<HTMLElementTagNameMap[T][P]> }, appendToParent?: Element): HTMLElementTagNameMap[T]
Create a DOM Element with any optional attributes or properties.
It will only accept valid DOM element properties that `createElement` would accept.
For example: `createDomElement('div', { className: 'my-css-class' })`,
for style or dataset you need to use nested object `{ style: { display: 'none' }}
The last argument is to optionally append the created element to a parent container element.
| Parameter | Type | Description |
|---|
tagName | T | - html tag |
elementOptions? | null | { [P in K]: InferDOMType<HTMLElementTagNameMap[T][P]> } | |
appendToParent? | Element | - parent element to append to |
returns HTMLElementTagNameMap[T]
getHtmlStringOutput
getHtmlStringOutput(input: DocumentFragment | HTMLElement | string | number, type?: 'innerHTML' | 'outerHTML'): string
From any input provided, return the HTML string (when a string is provided, it will be returned "as is" but when it's a number it will be converted to string)
When detecting HTMLElement/DocumentFragment, we can also specify which HTML type to retrieve innerHTML or outerHTML.
We can get the HTML by looping through all fragment `childNodes`
| Parameter | Type | Description |
|---|
input | DocumentFragment | HTMLElement | string | number | |
type? | 'innerHTML' | 'outerHTML' | - when the input is a DocumentFragment or HTMLElement, which type of HTML do you want to return? 'innerHTML' or 'outerHTML' |
returns string
emptyElement
emptyElement(element?: T | null): T | undefined | null
| Parameter | Type | Description |
|---|
element? | T | null | |
returns T | undefined | null
classNameToList
classNameToList(className?): string[]
Accepts string containing the class or space-separated list of classes, and
returns list of individual classes.
Method properly takes into account extra whitespaces in the `className`
e.g.: " class1 class2 " => will result in `['class1', 'class2']`.
| Parameter | Type | Description |
|---|
className? | | - space separated list of class names |
returns string[]
innerSize
innerSize(elm: HTMLElement, type: 'height' | 'width')
| Parameter | Type | Description |
|---|
elm | HTMLElement | |
type | 'height' | 'width' | |
isDefined
isDefined(value: T | undefined | null): value is T
| Parameter | Type | Description |
|---|
value | T | undefined | null | |
returns value is T
getElementProp
getElementProp(elm: HTMLElement & { getComputedStyle?: () => CSSStyleDeclaration }, property: string)
| Parameter | Type | Description |
|---|
elm | HTMLElement & { getComputedStyle?: () => CSSStyleDeclaration } | |
property | string | |
getFunctionDetails
getFunctionDetails(fn: AnyFunction, addReturn?)
Get the function details (param & body) of a function.
It supports regular function and also ES6 arrow functions
| Parameter | Type | Description |
|---|
fn | AnyFunction | - function to analyze |
addReturn? | | - when using ES6 function as single liner, we could add the missing `return ...` |
insertAfterElement
insertAfterElement(referenceNode: HTMLElement, newNode: HTMLElement)
| Parameter | Type | Description |
|---|
referenceNode | HTMLElement | |
newNode | HTMLElement | |
isEmptyObject
isEmptyObject(obj: any)
| Parameter | Type | Description |
|---|
obj | any | |
noop
noop()
offset
offset(el: HTMLElement | null)
| Parameter | Type | Description |
|---|
el | HTMLElement | null | |
windowScrollPosition
windowScrollPosition()
width
width(el: HTMLElement, value?: number | string): number | void
| Parameter | Type | Description |
|---|
el | HTMLElement | |
value? | number | string | |
returns number | void
height
height(el: HTMLElement, value?: number | string): number | void
| Parameter | Type | Description |
|---|
el | HTMLElement | |
value? | number | string | |
returns number | void
setStyleSize
setStyleSize(el: HTMLElement, style: keyof P, val?: number | string | Function): void
| Parameter | Type | Description |
|---|
el | HTMLElement | |
style | keyof P | |
val? | number | string | Function | |
returns void
setStyles
setStyles(element: T, styles: P): void
| Parameter | Type | Description |
|---|
element | T | |
styles | P | |
returns void
contains
contains(parent: HTMLElement, child: HTMLElement)
| Parameter | Type | Description |
|---|
parent | HTMLElement | |
child | HTMLElement | |
isHidden
isHidden(el: HTMLElement)
| Parameter | Type | Description |
|---|
el | HTMLElement | |
parents
parents(el: HTMLElement | ParentNode, selector?: string)
| Parameter | Type | Description |
|---|
el | HTMLElement | ParentNode | |
selector? | string | |
toFloat
toFloat(value: string | number)
| Parameter | Type | Description |
|---|
value | string | number | |
show
show(el: HTMLElement | HTMLElement[], type?)
| Parameter | Type | Description |
|---|
el | HTMLElement | HTMLElement[] | |
type? | | |
hide
hide(el: HTMLElement | HTMLElement[])
| Parameter | Type | Description |
|---|
el | HTMLElement | HTMLElement[] | |
slideUp
slideUp(el: HTMLElement | HTMLElement[], callback: Function)
| Parameter | Type | Description |
|---|
el | HTMLElement | HTMLElement[] | |
callback | Function | |
slideDown
slideDown(el: HTMLElement | HTMLElement[], callback: Function)
| Parameter | Type | Description |
|---|
el | HTMLElement | HTMLElement[] | |
callback | Function | |
slideAnimation
slideAnimation(el: HTMLElement | HTMLElement[], slideDirection: 'slideDown' | 'slideUp', callback: Function)
| Parameter | Type | Description |
|---|
el | HTMLElement | HTMLElement[] | |
slideDirection | 'slideDown' | 'slideUp' | |
callback | Function | |
applyDefaults
applyDefaults(targetObj: any, srcObj: any)
| Parameter | Type | Description |
|---|
targetObj | any | |
srcObj | any | |
addSlickEventPubSubWhenDefined
addSlickEventPubSubWhenDefined(pubSub?: BasePubSub, scope?: T)
User could optionally add PubSub Service to SlickEvent
When it is defined then a SlickEvent `notify()` call will also dispatch it by using the PubSub publish() method
| Parameter | Type | Description |
|---|
pubSub? | BasePubSub | |
scope? | T | |
SelectionUtils 7
normaliseDragRange
normaliseDragRange(rawRange: DragRange)
| Parameter | Type | Description |
|---|
rawRange | DragRange | |
copyRangeIsLarger
copyRangeIsLarger(baseRange: SlickRange, copyToRange: SlickRange): boolean
| Parameter | Type | Description |
|---|
baseRange | SlickRange | |
copyToRange | SlickRange | |
returns boolean
normalRangeOppositeCellFromCopy
normalRangeOppositeCellFromCopy(normalisedDragRange: DragRange, targetCell: { row: number; cell: number }): { row: number; cell: number }
Returns the anchor (opposite) cell to use while dragging the drag-extend handle.
Anchoring on the range start lets the drag shrink the range (Excel behavior), while dragging
past the start anchors on the range end so that it expands in the opposite direction instead.
| Parameter | Type | Description |
|---|
normalisedDragRange | DragRange | |
targetCell | { row: number; cell: number } | |
returns { row: number; cell: number }
verticalTargetRange
verticalTargetRange(baseRange: SlickRange, copyToRange: SlickRange)
| Parameter | Type | Description |
|---|
baseRange | SlickRange | |
copyToRange | SlickRange | |
horizontalTargetRange
horizontalTargetRange(baseRange: SlickRange, copyToRange: SlickRange)
| Parameter | Type | Description |
|---|
baseRange | SlickRange | |
copyToRange | SlickRange | |
cornerTargetRange
cornerTargetRange(baseRange: SlickRange, copyToRange: SlickRange)
| Parameter | Type | Description |
|---|
baseRange | SlickRange | |
copyToRange | SlickRange | |
copyCellsToTargetRange
copyCellsToTargetRange(baseRange: SlickRange, targetRange: SlickRange, grid: SlickGrid)
| Parameter | Type | Description |
|---|
baseRange | SlickRange | |
targetRange | SlickRange | |
grid | SlickGrid | |
RowPositionIndexer 4
RowPositionIndexer - a prefix-sum index of row top positions, used by SlickGrid when variable
row height mode is enabled (i.e. when a `rowHeightProvider` grid option is supplied).
`rowPos[i]` holds the virtual top pixel position of row `i` (i.e. the summed heights of all
preceding rows) and `rowPos[rowCount]` holds the total height of all indexed rows, which makes
row-to-position lookups an O(1) array read and position-to-row lookups an O(log n) binary search.
Row indexes are expected to be 0 or greater (guaranteed by the grid core; user-provided indexes
are validated in the public grid methods). Rows at or beyond the indexed range extrapolate
linearly using the default row height, mirroring the fixed-row-height arithmetic it replaces
(needed for the Add-New row and `leaveSpaceForNewRows` padding).
rebuild
rebuild(rowCount: number, defaultRowHeight: number, getRowHeight: (row: number) => number | undefined): void
Rebuilds the index by querying the height of every row. O(n) - the provided callback is
called once per row and must therefore be fast (a simple lookup, no DOM access).
| Parameter | Type | Description |
|---|
rowCount | number | - The number of rows to index. |
defaultRowHeight | number | - The height used when the callback returns `undefined` and for extrapolating beyond the indexed range. |
getRowHeight | (row: number) => number | undefined | - Returns the height of a row in pixels, or `undefined` to use the default. |
returns void
top
top(row: number): number
Returns the virtual top pixel position of a row.
| Parameter | Type | Description |
|---|
row | number | - The row index (>= 0); indexes beyond the indexed range extrapolate using the default row height. |
returns number
height
height(row: number): number
Returns the height of a row.
| Parameter | Type | Description |
|---|
row | number | - The row index (>= 0); indexes beyond the indexed range return the default row height. |
returns number
rowAt
rowAt(y: number): number
Returns the index of the row containing a virtual vertical pixel position.
Positions below zero return row 0; positions beyond the indexed range extrapolate using the
default row height (results may be beyond the last row - callers clamp, as in fixed mode).
| Parameter | Type | Description |
|---|
y | number | - The virtual vertical position in pixels. |
returns number