Home > widget-integration > FilterHandler > getIndexOfProductItem

FilterHandler.getIndexOfProductItem() method

Gets the index of a product item within the product list.

Searches through all product items in the boost-sd__product-list container to find the index position of the specified target item. This is used for pagination calculations and analytics tracking. Override this method to customize how product indices are determined (e.g., filtering out specific items).

Signature:

protected getIndexOfProductItem(targetItem: Element): number;

Parameters

Parameter

Type

Description

targetItem

Element

The target product item element to find

Returns:

number

The zero-based index of the product item, or -1 if not found

Example

Extend to exclude certain products from index calculation:

window.boostWidgetIntegration.extend('FilterHandler', (FilterHandler) => {
  return class CustomFilterHandler extends FilterHandler {
    protected getIndexOfProductItem(targetItem) {
      const document = this.filterStore.getState('document');
      // Exclude banner items from index calculation
      const productItems = Array.from(
        document.querySelectorAll('.boost-sd__product-list .boost-sd__product-item')
      ).filter(item => !item.classList.contains('boost-sd__product-item--banner'));

      return productItems.indexOf(targetItem);
    }
  };
});