Class ListView

Displays data items in a customizable list or grid.

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(element?: HTMLElement, options?: any): ListView

Creates a new ListView.

constructor

Parameters

  • element?: HTMLElement optional

    The DOM element that hosts the ListView control.

  • options?: any optional

    An object that contains one or more property/value pairs to apply to the new control. Each property of the options object corresponds to one of the control's properties or events. Event names must begin with "on". For example, to provide a handler for the selectionchanged event, add a property named "onselectionchanged" to the options object and set its value to the event handler.

Returns

ListView

Properties

public automaticallyLoadPages: boolean

Gets or sets a value that indicates whether the next set of pages is automatically loaded when the user scrolls beyond the number of pages specified by the pagesToLoadThreshold property.

public currentItem: IListViewItem

Gets or sets an IListViewItem that indicates which item should have keyboard focus and the focus state of that item.

public element: HTMLElement

Gets the HTML element that hosts this ListView.

public groupDataSource: IListDataSource

Gets or sets the data source that contains the groups for the items in the itemDataSource.

public groupHeaderTapBehavior: GroupHeaderTapBehavior

Gets or sets how the ListView reacts when the user taps or clicks a group header.

public groupHeaderTemplate: any

Gets or sets the Template or function that creates the DOM elements for each group header in the groupDataSource. Each group header can contain multiple elements, but it must have a single root element.

public indexOfFirstVisible: number

Gets or sets the first visible item.

public indexOfLastVisible: number

Gets the index of the last visible item in the ListView.

public itemDataSource: IListDataSource

Gets or sets the data source that provides the ListView with items.

public itemTemplate: any

Gets or sets the WinJS.Binding.Template or templating function that creates the DOM elements for each item in the itemDataSource. Each item can contain multiple elements, but it must have a single root element.

public itemsDraggable: boolean

Go Gets or sets a value that specifies whether items can be dragged. When this is set to true the ListView provides built in behaviors related to item dragging.

public itemsReorderable: boolean

Gets or sets whether the ListView control's items can be reordered within itself by dragging and dropping.

public layout: ILayout2

Gets or sets an object that controls the layout of the ListView.

public loadingBehavior: string

Gets or sets a value that specifies how the ListView fetches items and adds and removes them to the DOM. Don't change the value of this property after the ListView has begun loading data.

public loadingState: string

Gets a value that indicates whether the ListView is still loading or whether loading is complete.

public maxDeferredItemCleanup: number

Gets or sets the maximum number of realized items.

public pagesToLoad: number

Gets or sets the number of pages to load when the loadingBehavior property is set to "incremental" and the user scrolls beyond the threshold specified by the pagesToLoadThreshold property.

public pagesToLoadThreshold: number

Gets or sets the threshold (in pages) for initiating an incremental load. When the last visible item is within the specified number of pages from the end of the loaded portion of the list, and if automaticallyLoadPages is true and loadingBehavior is set to "incremental", the ListView initiates an incremental load.

public resetGroupHeader: (header: any, element: HTMLElement) => void

Gets or sets the function that is called when the ListView discards or recycles the element representation of a group header.

public resetItem: (item: T, element: HTMLElement) => void

Gets or sets the function that is called when an item is removed, an item is changed, or an item falls outside of the realized range of the ListView.

public scrollPosition: number

Gets or sets the distance, in pixels, of the start of the viewable area within the viewport.

public selection: ISelection

Gets an ISelection that contains the range of currently selected items.

public selectionMode: SelectionMode

Gets or sets the selection mode of the ListView.

public swipeBehavior: SwipeBehavior

Gets or sets how the ListView reacts to the swipe gesture. The swipe gesture can select the swiped items or can have no effect on the current selection.

public tapBehavior: TapBehavior

Gets or sets how the ListView reacts when the user taps or clicks an item.

public zoomableView: IZoomableView

Gets a ZoomableView that supports semantic zoom functionality. This API supports the SemanticZoom infrastructure and is not intended to be used directly from your code.

Methods

public addEventListener(eventName: string, eventHandler: Function, useCapture?: boolean)

Registers an event handler for the specified event.

Parameters

  • eventName: string

    The name of the event to handle. See the ListView object page for a list of events. Note that you drop the "on" when specifying the event name for the addEventListener method. For example, instead of specifying "onselectionchange", you specify "selectionchange".

  • eventHandler: Function

    The event handler function to associate with the event.

  • useCapture?: boolean optional

    Set to true to register the event handler for the capturing phase; otherwise, set to false to register the event handler for the bubbling phase.

public dispatchEvent(type: string, eventProperties: any): boolean

Raises an event of the specified type and with additional properties.

Parameters

  • type: string

    The type (name) of the event.

  • eventProperties: any

    The set of additional properties to be attached to the event object when the event is raised.

Returns

boolean

true if preventDefault was called on the event, otherwise false.

public dispose()

Releases resources held by this object. Call this method when the object is no longer needed. After calling this method, the object becomes unusable.

public elementFromIndex(itemIndex: number): HTMLElement

Returns the DOM element that represents the item at the specified index.

Parameters

  • itemIndex: number

    The index of the item.

Returns

HTMLElement

The DOM element that represents the item at the specified index.

public ensureVisible(itemIndex: number)

Makes the item at the specified index visible. If necessary, the ListView will scroll to the item.

Parameters

  • itemIndex: number

    The index of the item to scroll into view.

public forceLayout()

Forces the ListView to update its layout. Use this function when making the ListView visible again after its style.display property had been set to "none".

public indexOfElement(element: HTMLElement): number

Returns the index of the item that the specified DOM element displays.

Parameters

  • element: HTMLElement

    The DOM element that displays the item.

Returns

number

The index of the item displayed by element.

public loadMorePages()

Loads the next set of pages if the ListView control's loadingBehavior is set to "incremental" (otherwise, it does nothing). The number of pages to be loaded is determined by the pagesToLoad property.

public oncontentanimating(eventInfo: CustomEvent)

Occurs when the ListView is about to play an entrance or contentTransition animation.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.type, detail.setPromise.

public ongroupheaderinvoked(eventInfo: CustomEvent)

Raised when the user taps or clicks a group header.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.groupHeaderIndex, detail.groupHeaderPromise.

public onitemdragbetween(eventInfo: CustomEvent)

Raised when the ListView is a drop target and the onitemdragenter has been disabled. This is raised every time the cursor is moved between a new pair of items. If you call preventDefault on this event, then the ListView does not move the items slightly above/below the cursor to provide visual feedback for a drop.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains additional information about the event.

public onitemdragchanged(eventInfo: CustomEvent)

Raised when the user is dragging an item from the ListView and the datasource changes while the user is dragging.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains additional information about the event.

public onitemdragdrop(eventInfo: CustomEvent)

Raised when an item is dropped onto the ListView as the result of a drag operation.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.dataTransfer, detail.index, detail.insertAfterIndex.

public onitemdragend(eventInfo: CustomEvent)

Raised when the user drops an item dragged from a ListView.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event.

public onitemdragenter(eventInfo: CustomEvent)

Raised when an dragged item enters the bounds of the ListView control.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.dataTransfer.

public onitemdragleave(eventInfo: CustomEvent)

Raised when a draggable item leaves the bounds of a ListView control.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event.

public onitemdragstart(eventInfo: CustomEvent)

Raised when the user begins to drag an item from a ListView control.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.dataTransfer, detail.dragInfo.

public oniteminvoked(eventInfo: CustomEvent)

Occurs when the user taps or clicks an item.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.itemIndex.

public onkeyboardnavigating(eventInfo: CustomEvent)

Raised when the focused item changes.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.oldFocus, detail.oldNewFocus.

public onloadingstatechanged(eventInfo: CustomEvent)

Occurs when the ListView control's loadingState changes.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.scrolling.

public onselectionchanged(eventInfo: CustomEvent)

Occurs after the current selection changes.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object is null. To obtain the selected items, use the ListView.selection property.

public onselectionchanging(eventInfo: CustomEvent)

Occurs just before the current selection changes.

Parameters

  • eventInfo: CustomEvent

    An object that contains information about the event. The detail property of this object contains the following sub-properties: detail.newSelection, detail.preventTapBehavior.

public recalculateItemPosition()

Repositions all the visible items in the ListView to adjust for items whose sizes have changed. Most apps won’t ever need to call this method. For more info, see the Remarks section.

public removeEventListener(eventName: string, eventCallback: Function, useCapture?: boolean)

Removes an event handler that the addEventListener method registered.

Parameters

  • eventName: string

    The name of the event that the event handler is registered for.

  • eventCallback: Function

    The event handler function to remove.

  • useCapture?: boolean optional

    Set to true to remove the capturing phase event handler; set to false to remove the bubbling phase event handler.

public static triggerDispose()

Triggers the ListView disposal service manually.