File

projects/i-components/src/lib/services/grid.service.ts

Description

Service to make custom generic logic for the Grid and its children.

Index

Properties
Methods

Methods

checkForGridAutoDefinitions
checkForGridAutoDefinitions(gridModel: GridModel)

Checks if the grid has Auto Definitions.

Parameters :
Name Type Optional
gridModel GridModel No
Returns : void
hasGridAutoColumn
hasGridAutoColumn(gridModel: GridModel)

Checks if the grid has a column with auto width.

Parameters :
Name Type Optional
gridModel GridModel No
Returns : boolean
setControlAutoColumnClass
setControlAutoColumnClass(gridModel: GridModel)

Sets the autoColumn flag in case a child is inside an auto column.

Parameters :
Name Type Optional
gridModel GridModel No
Returns : void

Properties

Public newAutoColumnControlFound
Type : SubscriptionEvent<void>
Default value : new SubscriptionEvent()

Notifies the control in case an Auto Column is found.

import { Injectable } from '@angular/core';
import { GridModel, SubscriptionEvent } from '@mobilize/wms-framework';

/**
 * Service to make custom generic logic for the Grid and its children.
 *
 * @export
 * @class GridService
 */
@Injectable({
  providedIn: 'root',
})
export class GridService {
  /**
   * Notifies the control in case an Auto Column is found.
   *
   * @memberof GridService
   */
  public newAutoColumnControlFound: SubscriptionEvent<() => void> =
    new SubscriptionEvent();

  /**
   * Checks if the grid has Auto Definitions.
   *
   * @param {GridModel} gridModel
   * @memberof GridService
   */
  checkForGridAutoDefinitions(gridModel: GridModel) {
    if (this.hasGridAutoColumn(gridModel)) {
      this.setControlAutoColumnClass(gridModel);
    }
  }

  /**
   * Sets the autoColumn flag in case a child is inside an auto column.
   *
   * @param {GridModel} gridModel
   * @memberof GridService
   */
  setControlAutoColumnClass(gridModel: GridModel) {
    const children = gridModel?.Children?.internalArray;
    if (children?.length > 0) {
      children.forEach((child) => {
        const column = GridModel.GetColumn(child as any);
        const columnsArray = gridModel?.ColumnDefinitions?.internalArray;
        /* istanbul ignore else */
        if (columnsArray && columnsArray[column]?.Width.IsAuto) {
          child.HasAutoColumnGridParent = true;
          this.newAutoColumnControlFound.fire([]);
        }
      });
    }
  }

  /**
   * Checks if the grid has a column with auto width.
   *
   * @param {GridModel} gridModel
   * @return {*}
   * @memberof GridService
   */
  hasGridAutoColumn(gridModel: GridModel): boolean {
    if (gridModel?.ColumnDefinitions?.internalArray) {
      for (const column of gridModel.ColumnDefinitions.internalArray) {
        /* istanbul ignore else */
        if (column.Width.IsAuto) {
          return true;
        }
      }
    }
    return false;
  }
}

result-matching ""

    No results matching ""