File

projects/wms-framework/src/lib/models/controls/XamGridModel.ts

Description

A class to represent the grid Editing Settings

Index

Properties

Properties

AllowEditing
Type : XamGridEditingType
IsEnterKeyEditingEnabled
Default value : false
IsF2EditingEnabled
Default value : false
IsMouseActionEditingEnabled
Default value : MouseEditingAction.DoubleClick
IsOnCellActiveEditingEnabled
Default value : false
import {
  DependencyObject,
  INotifyPropertyChanged,
  IValueConverter,
} from '../../basecomponentmodel';
import { Control } from '../../basecomponentmodel/Control';
import { Dependency } from '../../basecomponentmodel/Dependency';
import { DependencyProperty } from '../../basecomponentmodel/DependencyProperty';
import { DependencyPropertyChangedEventArgs } from '../../basecomponentmodel/DependencyPropertyChangedEventArgs';
import { RuntimeStyleInfo } from '../../basecomponentmodel/RuntimeStyleInfo';
import {
  IPagedCollectionView,
  iuAny,
  iuFirstOrDefault,
  ObservableCollection,
  SimpleList,
} from '../../baseframework/collections';
import { ReflectionHelper } from '../../baseframework/ReflectionSupport';
import { Debugger } from '../../diagnostics/Debugger';
import { AngularComponentId } from '../../helpers/AngularComponentId';
import { transformStyles } from '../../utils/StyleFunctions';
import { SubscriptionEvent } from '../../utils/SubscriptionEvent';
import { XamSelectionMode } from '../enums/SelectionMode';
import { SortDirection } from '../enums/SortDirection';
import { RoutedEventArgs } from '../events/RoutedEventArgs';
import { ActiveCellChangingEventArgs } from './ActiveCellChangingEventArgs';
import { CancellableEventArgs } from './CancellableEventArgs';
import { CellAlignment } from './CellAlignment';
import { CellBase } from './CellBase';
import { ChildBandCell } from './ChildBandCell';
import { ColumnLayout } from './ColumnLayout';
import { ContentControlModel } from './ContentControlModel';
import { ColumnWidth } from './DataGridLengthModel';
import { FilterRow } from './FilterRow';
import { InvokeAction } from './InvokeAction';
import { RowBase } from './RowBase';
import { RowCollection } from './RowCollection';
import { RowsManager } from './RowsManager';
import { ThicknessModel } from './ThicknessModel';
import {
  XamGridColumnModel,
  XamGridGroupColumnModel,
} from './XamGridColumnModel';
import { XamGridRow } from './XamGridRow';
import { XamGridRowsManager } from './XamGridRowsManager';

/**
 *  Enumeration for specifying the kinds of overs
 *
 * @export
 * @enum {number}
 * @wEnum Infragistics.Controls.Grids.RowHoverType
 */
export enum RowHoverType {
  Cell,
  Row,
  None,
}

/**
 * Valid column types for XamGrid.
 *
 * @export
 */
export type XamGridColumnType = 'int' | 'decimal' | 'int?' | 'Nullable<int>';
/**
 *  Class that represents the Model of the XamGrid
 *
 * @export
 * @class XamGridModel
 * @extends {Control}
 * @wType Infragistics.Controls.Grids.XamGrid
 */
export class XamGridModel extends Control {
  /**
   * Custom Mobilize property to access the XamGridComponent.
   *
   * @type {*}
   * @memberof XamGridModel
   */
  gridComponentInstance: any = null;

  /**
   * Flag to prevent clearing Active Cell when CollectionChnged is triggered.
   *
   * @memberof XamGridModel
   * @wIgnore
   */
  PreventClearActiveCell = false;

  /**
   * SelectedRowProperty dependency property.
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   * @wIgnore
   */
  static SelectedRowProperty = new DependencyProperty(
    'SelectedRow',
    null,
    null
  );

  /**
   *  ActiveItemProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static ActiveItemProperty: DependencyProperty = new DependencyProperty(
    'ActiveItem',
    null,
    null
  );

  /**
   *  AutoGenerateColumnsProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static AutoGenerateColumnsProperty: DependencyProperty =
    new DependencyProperty('AutoGenerateColumns', true, null);

  /**
   *  CellControlGenerationModeProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static CellControlGenerationModeProperty: DependencyProperty =
    new DependencyProperty('CellControlGenerationMode', null, null);

  /**
   *  CellStyleProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static CellStyleProperty: DependencyProperty = new DependencyProperty(
    'CellStyle',
    null,
    null
  );

  /**
   *  ChildBandHeaderHeightProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static ChildBandHeaderHeightProperty: DependencyProperty =
    new DependencyProperty('ChildBandHeaderHeight', null, null);

  /**
   *  ChildBandHeaderStyleProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static ChildBandHeaderStyleProperty: DependencyProperty =
    new DependencyProperty('ChildBandHeaderStyle', null, null);

  /**
   *  ColumnLayoutHeaderVisibilityProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static ColumnLayoutHeaderVisibilityProperty: DependencyProperty =
    new DependencyProperty('ColumnLayoutHeaderVisibility', null, null);

  /**
   *  ColumnsFooterTemplateProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static ColumnsFooterTemplateProperty: DependencyProperty =
    new DependencyProperty('ColumnsFooterTemplate', null, null);

  /**
   *  ColumnWidthProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static ColumnWidthProperty: DependencyProperty =
    new DependencyProperty('ColumnWidth', ColumnWidth.InitialAuto, null);

  /**
   *  DeleteKeyActionProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static DeleteKeyActionProperty: DependencyProperty =
    new DependencyProperty('DeleteKeyAction', null, null);

  /**
   *  FixedRowSeparatorStyleProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static FixedRowSeparatorStyleProperty: DependencyProperty =
    new DependencyProperty('FixedRowSeparatorStyle', null, null);

  /**
   *  FooterRowHeightProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static FooterRowHeightProperty: DependencyProperty =
    new DependencyProperty('FooterRowHeight', null, null);

  /**
   * FooterStyleProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static FooterStyleProperty: DependencyProperty =
    new DependencyProperty('FooterStyle', null, null);

  /**
   *  FooterVisibilityProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static FooterVisibilityProperty: DependencyProperty =
    new DependencyProperty('FooterVisibility', false, null);

  /**
   *  HeaderRowHeightProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static HeaderRowHeightProperty: DependencyProperty =
    new DependencyProperty('HeaderRowHeight', null, null);

  /**
   *  HeaderStyleProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static HeaderStyleProperty: DependencyProperty =
    new DependencyProperty(
      'HeaderStyle',
      null,
      XamGridModel.TransformStyleCallback
    );

  /**
   *  HeaderTemplateProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static HeaderTemplateProperty: DependencyProperty =
    new DependencyProperty('HeaderTemplate', null, null);

  /**
   *  HeaderTextHorizontalAlignmentProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static HeaderTextHorizontalAlignmentProperty: DependencyProperty =
    new DependencyProperty('HeaderTextHorizontalAlignment', null, null);

  /**
   *  HeaderTextVerticalAlignmentProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static HeaderTextVerticalAlignmentProperty: DependencyProperty =
    new DependencyProperty('HeaderTextVerticalAlignment', null, null);

  /**
   *  HeaderVisibilityProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static HeaderVisibilityProperty: DependencyProperty =
    new DependencyProperty('HeaderVisibility', null, null);

  /**
   *  IndentationProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static IndentationProperty: DependencyProperty =
    new DependencyProperty('Indentation', null, null);

  /**
   *  IsAlternateRowsEnabledProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static IsAlternateRowsEnabledProperty: DependencyProperty =
    new DependencyProperty('IsAlternateRowsEnabled', false, null);

  /**
   *  IsTouchSupportEnabledProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static IsTouchSupportEnabledProperty: DependencyProperty =
    new DependencyProperty('IsTouchSupportEnabled', null, null);

  /**
   *  ItemsSourceProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static ItemsSourceProperty: DependencyProperty =
    new DependencyProperty(
      'ItemsSource',
      null,
      XamGridModel.itemsSourceCallback
    );

  /**
   *  KeyboardNavigationProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static KeyboardNavigationProperty: DependencyProperty =
    new DependencyProperty('KeyboardNavigation', null, null);

  /**
   *  MaxDepthProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static MaxDepthProperty: DependencyProperty = new DependencyProperty(
    'MaxDepth',
    null,
    null
  );

  /**
   *  MinimumRowHeightProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static MinimumRowHeightProperty: DependencyProperty =
    new DependencyProperty('MinimumRowHeight', null, null);

  /**
   *  RowHeightProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static RowHeightProperty: DependencyProperty = new DependencyProperty(
    'RowHeight',
    null,
    null
  );

  /**
   *  RowHoverProperty dependency property
   *
   * @static
   * @type {DependencyProperty}
   * @memberof XamGridModel
   */
  public static RowHoverProperty: DependencyProperty = new DependencyProperty(
    'RowHover',
    RowHoverType.Cell,
    null
  );
  private readonly _rowsManager: XamGridRowsManager;

  /**
   * Keeps the current edit cell
   *
   * @type {XamGridCell}
   * @memberof XamGridModel
   */
  public CurrentEditCell: XamGridCell;

  /**
   * Keeps the current edit row
   *
   * @type {XamGridRow}
   * @memberof XamGridModel
   */
  public CurrentEditRow: XamGridRow;

  /**
   * Sets the grid height to limit how many rows are rendered
   * accepts null value, which will render all rows in the DOM with no scrollbar
   *
   * @type {string|null}
   * @memberof XamGridModel
   */
  virtualHeight: string | null = '100%';

  /**
   * Keeps the current active cell
   *
   * @private
   * @type {CellBase}
   * @memberof XamGridModel
   */
  private _activeCell: CellBase;

  /**
   * Mobilize callback to set the ActiveCell when the igx-grid is rendered
   *
   * @type {*}
   * @memberof XamGridModel
   */
  contextActiveCell: () => void;

  /**
   * Internal property to keep the current Selection setting for the xamGrid
   *
   * @private
   * @type {SelectionSettings}
   * @memberof XamGridModel
   */
  private _selectionSettings: SelectionSettings;

  /**
   * returns the rowsManager instance, which is responsible for managing the rows of the grid
   * this is a custom property created by Mobilize team to access the rowsManager
   * @readonly
   * @protected
   * @type {XamGridRowsManager}
   * @memberof XamGridModel
   */
  public get RowsManager(): XamGridRowsManager {
    return this._rowsManager;
  }

  /**
   * Triggers a special model change event when ItemsSource changes.
   *
   * @private
   * @static
   * @param {DependencyObject} sender
   * @param {DependencyPropertyChangedEventArgs} args
   * @memberof XamGridModel
   */
  private static itemsSourceCallback(
    sender: DependencyObject,
    args: DependencyPropertyChangedEventArgs
  ) {
    if (sender instanceof XamGridModel) {
      sender.ItemsSourceAsPagedCollection = null;
      if (
        args.NewValue &&
        ReflectionHelper.isInterfaceIsSupported(
          args.NewValue,
          'System.ComponentModel.IPagedCollectionView'
        )
      ) {
        sender.ItemsSourceAsPagedCollection = args.NewValue;
      }
      sender.ApplyItemSource(args.NewValue as Iterable<any>);
      sender.change.fire(['ItemsSourceChanged', args]);
    }
  }
  /**
   * Applies the Item source
   *
   * @param {Iterable<any>} itemSource
   * @memberof XamGridModel
   * @wIgnore
   */
  ApplyItemSource(itemSource: Iterable<any>) {
    if (this._rowsManager.ItemsSource !== itemSource) {
      this._rowsManager.ItemsSource = itemSource;
      this.SortingSettings.SortedColumns?.clear();
    }
  }

  /**
   * Creates an instance of XamGridModel.
   * @memberof XamGridModel
   */
  constructor() {
    super();
    this._rowsManager = new XamGridRowsManager(this);
  }

  /**
   * Notify this model of a data update.
   *
   * @memberof XamGridModel
   * @wIgnore
   */
  public NotifyDataUpdate(): void {
    this.adjustColumnTypesBasedOnNewData();
    this.change.fire(['DataUpdate']);
  }

  /**
   *  Adjust column DataType properties based on new data
   *
   * @private
   * @static
   * @param {DependencyPropertyChangedEventArgs} args
   * @param {XamGridModel} sender
   * @memberof XamGridModel
   */
  public adjustColumnTypesBasedOnNewData(): void {
    if (
      !this.dataColumnInfoAdjusted &&
      this.ItemsSource &&
      this.Columns.count > 0 &&
      this.ItemsSource[Symbol.iterator]
    ) {
      const firstRow = iuFirstOrDefault(this.ItemsSource);
      if (
        firstRow &&
        typeof firstRow === 'object' &&
        firstRow.constructor !== Object
      ) {
        const typeInfo = ReflectionHelper.getTypeInfo(firstRow);
        for (const textColumn of this.Columns) {
          if (textColumn.Key in firstRow) {
            const propInfo = typeInfo.getProperty(textColumn.Key);
            if (propInfo.propertyType?.JSType === Date) {
              textColumn.DataType = 'date';
            }
          }
        }
        this.dataColumnInfoAdjusted = true;
      }
    }
  }

  public AngularComponentId = AngularComponentId.xamGrid;

  /**
   * Rendered subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  Rendered = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  /**
   * Loaded subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  Loaded = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  /**
   * Unloaded subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  Unloaded = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  /**
   * CellSelectionChanged subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  CellSelectionChanged = new SubscriptionEvent<
    (s: XamGridModel, e: any) => void
  >();
  /**
   * RowSelectionChanged subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  RowSelectionChanged = new SubscriptionEvent<
    (s: XamGridModel, e: any) => void
  >();
  /**
   * RowsCollectionChanged subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  RowsCollectionChanged = new SubscriptionEvent<
    (s: XamGridModel, e: any) => void
  >();
  /**
   * ColumnSelectionChanged subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  ColumnSelectionChanged = new SubscriptionEvent<
    (s: XamGridModel, e: any) => void
  >();
  ColumnSorted = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  ColumnSorting = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  /**
   * ColumnFiltered subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  ColumnFiltered = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  ColumnResized = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  ColumnResizing = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  ColumnFixedStateChanged = new SubscriptionEvent<
    (s: XamGridModel, e: any) => void
  >();
  CellClicked = new SubscriptionEvent<
    (s: XamGridModel, e: CellClickedEventArgs) => void
  >();
  CellControlAttached = new SubscriptionEvent<
    (s: XamGridModel, e: CellControlAttachedEventArgs) => void
  >();
  /**
   * AfterCellControlAttached subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  AfterCellControlAttached = new SubscriptionEvent<
    (s: XamGridModel, e: CellControlAttachedEventArgs) => void
  >();
  CellDoubleClicked = new SubscriptionEvent<
    (s: XamGridModel, e: any) => void
  >();
  /**
   * KeyDown subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  KeyDown = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  ActiveCellChanged = new SubscriptionEvent<
    (s: XamGridModel, e: any) => void
  >();
  ActiveCellChanging = new SubscriptionEvent<
    (s: XamGridModel, e: any) => void
  >();
  CellEnteredEditMode = new SubscriptionEvent<
    (s: XamGridModel, e: EditingCellEventArgs) => void
  >();
  SelectedRowsCollectionChanged: SubscriptionEvent<any> =
    new SubscriptionEvent<any>();
  CellExitingEditMode = new SubscriptionEvent<
    (s: XamGridModel, e: ExitEditingCellEventArgs) => void
  >();
  CellExitedEditMode = new SubscriptionEvent<
    (s: XamGridModel, e: CellExitedEditingEventArgs) => void
  >();
  CellEnteringEditMode = new SubscriptionEvent<
    (s: XamGridModel, e: BeginEditingCellEventArgs) => void
  >();
  /**
   * CellEditing subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  CellEditing = new SubscriptionEvent<
    (s: XamGridModel, e: EditingCellEventArgs) => void
  >();
  /**
   * CellEdited subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  CellEdited = new SubscriptionEvent<
    (s: XamGridModel, e: ExitEditingCellEventArgs) => void
  >();
  InitializeRow = new SubscriptionEvent<
    (s: XamGridModel, e: InitializeRowEventArgs) => void
  >();
  PageIndexChanged = new SubscriptionEvent<
    (s: XamGridModel, e: PageChangedEventArgs) => void
  >();
  PageIndexChanging = new SubscriptionEvent<
    (s: XamGridModel, e: CancellablePageChangingEventArgs) => void
  >();
  RowAdded = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  RowDeleted = new SubscriptionEvent<(s: XamGridModel, e: any) => void>();
  RowExitedEditMode = new SubscriptionEvent<
    (s: XamGridModel, e: EditingRowEventArgs) => void
  >();
  RowEnteredEditMode = new SubscriptionEvent<
    (s: XamGridModel, e: EditingRowEventArgs) => void
  >();
  /**
   * ScrolledCellIntoView subscription event
   * @memberof XamGridModel
   * @wIgnore
   */
  ScrolledCellIntoView: SubscriptionEvent<(cell: XamGridCell) => void> =
    new SubscriptionEvent<(cell: XamGridCell) => void>();
  isEditableOnAdd: boolean;

  /**
   *  Flag to determine if the types of the column were adjusted based on new objects added to the items source
   *
   * @private
   * @memberof XamGridRow
   */
  private dataColumnInfoAdjusted = false;

  /**
   * Flag to manage when the editor template is loaded
   *
   * @type {boolean}
   * @memberof XamGridComponent
   */
  editorTemplateLoading = false;

  /**
   * Gets or sets the auto generate columns
   *
   * @memberof XamGridModel
   */
  @Dependency(XamGridModel.AutoGenerateColumnsProperty)
  AutoGenerateColumns: boolean;

  /**
   * Gets or sets the column width
   *
   * @memberof XamGridModel
   */
  @Dependency(XamGridModel.ColumnWidthProperty)
  ColumnWidth: ColumnWidth;

  /**
   * Gets or sets the IsAlternateRowsEnabled property
   *
   * @memberof XamGridModel
   */
  @Dependency(XamGridModel.IsAlternateRowsEnabledProperty)
  IsAlternateRowsEnabled: boolean;

  FilteringSettings = new FilteringSettings();

  /**
   * Gets or sets the footer visibility
   *
   * @memberof XamGridModel
   */
  @Dependency(XamGridModel.FooterVisibilityProperty)
  FooterVisibility: boolean;

  EditingSettings = new EditingSettings();

  /**
   * Gets or sets the header style
   *
   * @type {RuntimeStyleInfo}
   * @memberof XamGridModel
   */
  @Dependency(XamGridModel.HeaderStyleProperty)
  HeaderStyle: RuntimeStyleInfo;

  RowSelectorSettings = new RowSelectorSettings();
  /**
   * Gets or sets the row hover
   *
   * @memberof XamGridModel
   */
  @Dependency(XamGridModel.RowHoverProperty)
  RowHover: RowHoverType;

  PagerSettings = new PagerSettings();
  SortingSettings = new SortingSettings();
  FixedColumnSettings = new FixedColumnSettings();
  ColumnResizingSettings = new ColumnResizingSettings();
  ColumnMovingSettings = new ColumnMovingSettings();
  /**
   * Gets or sets the selected column index
   *
   * @memberof XamGridModel
   * @wIgnore
   */
  SelectedColumnIndex: any;
  BorderThickness: ThicknessModel = new ThicknessModel();
  BorderBrush: any;
  HeaderVisibility: any = 'visible';

  /**
   * headerStyleProperty css properties object used to apply
   *
   * @type {*}
   * @memberof XamGridModel
   * @wIgnore
   */
  HeaderStylePropertyToApply: any = {};

  /**
   * Callback function to transform style object.
   *
   * @static
   * @param {XamGridModel} sender
   * @param {DependencyPropertyChangedEventArgs} args
   * @memberof XamGridModel
   * @wIgnore
   */
  public static TransformStyleCallback(
    sender: XamGridModel,
    args: DependencyPropertyChangedEventArgs
  ) {
    const xamGridModel: any = sender;
    const newStyle = args.NewValue;
    /* istanbul ignore else */
    if (newStyle instanceof RuntimeStyleInfo) {
      transformStyles(
        xamGridModel.HeaderStylePropertyToApply,
        newStyle.Setters
      );
    }
  }

  /**
   * Gets the ActiveCell
   *
   * @type {CellBase}
   * @memberof XamGridModel
   */
  public get ActiveCell(): CellBase {
    return this._activeCell;
  }

  /**
   * Sets the ActiveCell
   *
   * @memberof XamGridModel
   */
  public set ActiveCell(value: CellBase) {
    this.SetActiveCell(
      value,
      CellAlignment.NotSet,
      InvokeAction.Code,
      true,
      true,
      true
    );
    /* istanbul ignore else */
    if (this._activeCell == null) {
      this.contextActiveCell = null;
      return;
    }
    const isOnCellActiveEditingEnabled =
      this.EditingSettings?.IsOnCellActiveEditingEnabled;
    const isReadOnly = this._activeCell.Column.IsReadOnly;
    this.contextActiveCell = () => {
      this.gridComponentInstance.processActiveCell(
        isOnCellActiveEditingEnabled,
        isReadOnly
      );
      this.contextActiveCell = null;
    };
    setTimeout(() => {
      /* istanbul ignore else */
      if (
        this.gridComponentInstance &&
        !this.gridComponentInstance.callProcessActiveCellFlag
      ) {
        this.gridComponentInstance.processActiveCell(
          isOnCellActiveEditingEnabled,
          isReadOnly
        );
      }
    }, 200);
  }

  /**
   * Set the active Cell for the xamGrid,
   * trigger events for OnActiveCellChanging and OnActiveCellChanged
   *
   * @param {CellBase} cell
   * @param {CellAlignment} alignment
   * @param {InvokeAction} action
   * @param {boolean} allowSelection
   * @param {boolean} setFocus
   * @param {boolean} scrollIntoView
   * @return {*}
   * @memberof XamGridModel
   */
  SetActiveCell(
    cell: CellBase,
    alignment: CellAlignment,
    action: InvokeAction,
    allowSelection: boolean,
    setFocus: boolean,
    scrollIntoView: boolean
  ) {
    if (cell != null) {
      if (!cell.Column.Visibility) {
        throw new Error('InvalidActiveCellException');
      }
    } else if (this.ActiveCell == null) {
      return;
    }
    if (cell != null && this.ActiveCell == cell) {
      if (cell.Control == null) {
        return;
      }
      if (cell.Control.Content instanceof Control) {
        cell.Control.Content.focus?.();
        return;
      }
    }
    if (scrollIntoView && cell != null && this.ActiveCell != cell && cell.Row) {
      this.ScrollCellIntoView(cell);
    }

    this.isInEditMode(cell);
    return this.ActiveLifeCycle(cell);
  }

  isInEditMode(cell: CellBase) {
    // the next to if statements are to prevent the active cell when the grid is in editmode!
    if (this.CurrentEditRow != null) {
      if (cell != null && cell.Row != this.CurrentEditRow) {
        this.ScrollCellIntoView(this.CurrentEditCell);
        return;
      }
    } else if (this.CurrentEditCell != null) {
      const currentEditCell = this.CurrentEditCell;
      // if true, we need to scroll the cell into view
      if (
        currentEditCell.Row instanceof FilterRow &&
        cell != null &&
        !(cell.Row instanceof FilterRow) &&
        currentEditCell.Row.RowsManager instanceof RowsManager
      ) {
        const dataManager = currentEditCell.Row.RowsManager.DataManager;
        if (dataManager != null) {
          if (dataManager.FilterItems.Count == 0) {
            return;
          }
        }
      }
    }
  }

  /**
   * Run the active life cycle of the activeNode process
   *
   * @private
   * @param {CellBase} cell
   * @return {*}
   * @memberof XamGridModel
   */
  private ActiveLifeCycle(cell: CellBase) {
    const cell2 = cell;
    if (cell2 == null && !(cell instanceof ChildBandCell)) {
      cell = null;
    }
    const activeCellChangingEventArgs = new ActiveCellChangingEventArgs();
    activeCellChangingEventArgs.NewActiveCell = cell;
    activeCellChangingEventArgs.PreviousActiveCell = this.ActiveCell;
    const activeCellChangingEventArgs2 = activeCellChangingEventArgs;
    this.OnActiveCellChanging(activeCellChangingEventArgs);
    if (!activeCellChangingEventArgs2.Cancel) {
      this._activeCell = cell;
      this.OnActiveCellChanged();
    }
    return cell;
  }

  OnActiveCellChanged() {
    this.ActiveCellChanged?.fire([this, {}]);
  }

  OnActiveCellChanging(e: ActiveCellChangingEventArgs) {
    this.ActiveCellChanging?.fire([this, e]);
  }

  /**
   * Flag to determine if the row should enter edit mode on add
   *
   * @memberof XamGridModel
   * @wIgnore
   */
  get IsEditableOnAdd(): boolean {
    return this.isEditableOnAdd;
  }

  /**
   * Sets the IsEditableOnAdd flag
   * @memberof XamGridModel
   * @wIgnore
   */
  set IsEditableOnAdd(value: boolean) {
    this.isEditableOnAdd = value;
  }

  /**
   * Selected row property
   * @memberof XamGridModel
   * @wIgnore
   */
  @Dependency(XamGridModel.SelectedRowProperty)
  public SelectedRow: any;

  /**
   * Gets or sets the items source
   *
   * @type {*}
   * @memberof XamGridModel
   */
  public get ItemsSource(): Iterable<any> {
    return this._rowsManager.ItemsSource;
  }

  public set ItemsSource(value: Iterable<any>) {
    this.setValue(XamGridModel.ItemsSourceProperty, value);
  }

  /**
   * SelectedIndex
   *
   * @type {*}
   * @memberof XamGridModel
   * @wIgnore
   */
  SelectedIndex: any;

  /**
   * SelectedItems
   *
   * @type {ObservableCollection<any>}
   * @memberof XamGridModel
   * @wIgnore
   */
  SelectedItems: ObservableCollection<any> = new ObservableCollection<any>();

  /**
   * SelectionSettings
   *
   * @memberof XamGridModel
   */
  get SelectionSettings(): SelectionSettings {
    if (this._selectionSettings == null) {
      this._selectionSettings = new SelectionSettings(
        this._rowsManager.ColumnLayout
      );
    }
    this._selectionSettings.Grid = this;
    return this._selectionSettings;
  }

  set SelectionSettings(value: SelectionSettings) {
    if (value !== this._selectionSettings) {
      this._selectionSettings = value;
    }
  }

  /**
   * Columns
   *
   * @memberof XamGridModel
   */
  get Columns(): ColumnBaseCollection {
    return this._rowsManager.ColumnLayout.Columns;
  }

  /**
   * Rows
   *
   * @memberof XamGridModel
   */
  get Rows(): RowCollection {
    return this._rowsManager.Rows.ActualCollection as any;
  }

  /**
   * addColumn
   *
   * @param {XamGridColumnModel} column
   * @memberof XamGridModel
   */
  public addColumn(column: XamGridColumnModel): void {
    this.setColumnInfo(column);
    this.Columns.add(column);
  }

  addVisualColumn(column: XamGridColumnModel): void {
    this.setColumnInfo(column);
    this.Columns.add(column);
  }

  /**
   * Sets the ColumnLayout for the row
   *
   * @private
   * @param {XamGridColumnModel} column
   * @memberof XamGridModel
   */
  private setColumnInfo(column: XamGridColumnModel) {
    column.ColumnLayout = this._rowsManager.ColumnLayout;
    column.Parent = this;
  }

  /**
   * getColumns
   *
   * @return {*}  {ColumnBaseCollection}
   * @memberof XamGridModel
   */
  public getColumns(): ColumnBaseCollection {
    return this.Columns;
  }

  /**
   * ScrollCellIntoView
   *
   * @param {*} cell
   * @memberof XamGridModel
   */
  public ScrollCellIntoView(cell: CellBase): void {
    if (cell instanceof XamGridCell && cell.Row.Index !== -1) {
      this.ScrolledCellIntoView.fire([cell]);
    }
  }

  /**
   * fire CellSelectionChangeHandler
   *
   * @param {*} event
   * @memberof XamGridModel
   * @wIgnore
   */
  public CellSelectionChangeHandler(event: any): void {
    this.CellSelectionChanged.fire([this, event]);
  }

  /**
   * ScrollIntoView
   *
   * @param {...any[]} args
   * @memberof XamGridModel
   * @wIgnore
   */
  public ScrollIntoView(...args: any[]): void {
    Debugger.Throw('Not implemented');
  }

  /**
   * Fire RowSelectionChangeHandler
   *
   * @param {*} event
   * @memberof XamGridModel
   * @wIgnore
   */
  public RowSelectionChangeHandler(event: any): void {
    this.RowSelectionChanged.fire([this, event]);
  }

  /**
   * Fire ColumnSelectionChangeHandler
   *
   * @param {*} event
   * @memberof XamGridModel
   * @wIgnore
   */
  public ColumnSelectionChangeHandler(event: any): void {
    this.ColumnSelectionChanged.fire([this, event]);
  }

  /**
   * KeyDownHandler
   *
   * @param {*} event
   * @memberof XamGridModel
   * @wIgnore
   */
  public KeyDownHandler(event: any): void {
    this.KeyDown.fire([this, event]);
  }

  /**
   * Fire CellDoubleClickHandler
   *
   * @param {*} event
   * @memberof XamGridModel
   * @wIgnore
   */
  public CellDoubleClickHandler(event: any): void {
    this.CellDoubleClicked.fire([this, event]);
  }

  /**
   *  Property containing a reference as a IPagedCollection or null
   *
   * @return {*}  {IPagedCollectionView}
   * @memberof XamGridModel
   * @wIgnore
   */
  public ItemsSourceAsPagedCollection: IPagedCollectionView = null;

  /**
   * Dispose
   *
   * @param {boolean} [disposing]
   * @memberof XamGridModel
   */
  public Dispose(disposing?: boolean) {
    Debugger.Throw('Not implemented');
  }

  /**
   * ExitEditMode
   *
   * @param {boolean} cancel
   * @memberof XamGridModel
   */
  public ExitEditMode(cancel: boolean) {
    this.change.fire(['triggerExitEditMode', !cancel]);
  }

  /**
   * ExitEditModeInternal
   *
   * @param {boolean} cancel
   * @memberof XamGridModel
   * @wNoMap
   */
  public ExitEditModeInternal(cancel: boolean) {
    Debugger.Throw('Not implemented');
  }

  /**
   * OnPropertyChanged
   *
   * @param {string} name
   * @memberof XamGridModel
   * @wNoMap
   */
  public OnPropertyChanged(name: string) {
    Debugger.Throw('Not implemented');
  }

  /**
   * On Got Focus handler for XamGrid
   *
   * @param {*} sender
   * @param {*} [args]
   * @memberof XamGridModel
   */
  public OnGotFocus(args: RoutedEventArgs): void {
    super.OnGotFocus(args);
    if (this.CurrentEditCell == null && this.ActiveCell == null) {
      if (this.Rows.count > 0 && this.Rows.getItem(0).Cells.count > 0) {
        const setFocus = true;
        for (let cell of this.Rows.getItem(0).Cells) {
          if (cell instanceof CellBase && cell.Column.Visibility) {
            this.SetActiveCell(
              cell,
              CellAlignment.NotSet,
              InvokeAction.Code,
              true,
              setFocus,
              false
            );
            break;
          }
        }
      }
    }
  }

  /**
   * Sets the data type associated with a column name. Valid examples
   * of column types are:
   * - 'int'
   * - 'decimal'
   * - 'int?'
   * - 'Nullable\<int\>'
   * - etc.
   *
   * @param {string} columnName
   * @param {XamGridColumnType} type
   * @memberof XamGridModel
   * @wIgnore
   */
  public SetColumnType(columnName: string, type: XamGridColumnType): void {
    this.columnTypes.set(columnName, type);
  }

  /**
   * Returns `true` if the given column name has an associated data type,
   * `false` otherwise.
   *
   * @param {string} columnName
   * @return {*}  {boolean}
   * @memberof XamGridModel
   * @wIgnore
   */
  public HasColumnType(columnName: string): boolean {
    return this.columnTypes.has(columnName);
  }

  /**
   * Returns the column data type associated with the given column name.
   *
   * @param {string} columnName
   * @return {*}  {string}
   * @memberof XamGridModel
   * @wIgnore
   */
  public GetColumnType(columnName: string): XamGridColumnType {
    return this.columnTypes.get(columnName);
  }

  /**
   * Clears selected rows.
   *
   * @memberof XamGridModel
   * @wIgnore
   */
  public ClearSelectedRows(): void {
    this.SelectionSettings.SelectedRows.clear();
    for (const row of this.Rows) {
      row.IsSelected = false;
    }
  }

  /**
   * A callback function to handle row selection
   *
   * @param {XamGridRow} row
   * @memberof XamGridModel
   */
  public SelectRow(row: XamGridRow): void {
    const selectedRows = this.SelectionSettings?.SelectedRows;
    let oldRows = selectedRows
      ? new SelectedRowsCollection(selectedRows.toArray())
      : new SelectedRowsCollection();
    let isChanged = false;

    if (
      selectedRows &&
      this.SelectionSettings?.RowSelection === XamSelectionMode.Single
    ) {
      if (
        selectedRows.count > 1 ||
        !iuAny(
          selectedRows,
          (anotherRow) => anotherRow == row || anotherRow.Data === row.Data
        )
      ) {
        selectedRows.clear();
        selectedRows.add(row);
        isChanged = true;
      }
    } else if (
      selectedRows &&
      !iuAny(
        selectedRows,
        (anotherRow) => anotherRow == row || anotherRow.Data === row.Data
      )
    ) {
      selectedRows.add(row);
      isChanged = true;
    }

    if (isChanged && this.SelectedRow != row) {
      // Fire SelectedRowsCollectionChanged event
      let newRows = new SelectedRowsCollection(selectedRows.toArray());
      const params = new SelectionCollectionChangedEventArgs();
      params.NewSelectedItems = new SelectedRowsCollection(newRows);
      params.PreviouslySelectedItems = new SelectedRowsCollection(oldRows);
      this.SelectedRowsCollectionChanged.fire([this, params]);
      this.RowSelectionChangeHandler(params);
    }
  }

  /**
   * A callback function to handle the unselection of rows
   *
   * @param {XamGridRow} row
   * @memberof XamGridModel
   */
  public UnselectRow(row: XamGridRow): void {
    const selectedRows = this.SelectionSettings?.SelectedRows;
    if (selectedRows == null) {
      return;
    }

    const unSelectedRow = iuFirstOrDefault(
      selectedRows,
      (each: XamGridRow) => each.Data === row.Data
    );
    let oldRows = new SelectedRowsCollection(selectedRows.toArray());
    if (unSelectedRow != null) {
      selectedRows.remove(unSelectedRow);
      let newRows = new SelectedRowsCollection(selectedRows.toArray());
      // Fire SelectedRowsCollectionChanged event
      const params = new SelectionCollectionChangedEventArgs();
      params.NewSelectedItems = new SelectedRowsCollection(newRows);
      params.PreviouslySelectedItems = new SelectedRowsCollection(oldRows);
      this.SelectedRowsCollectionChanged.fire([this, params]);
    }
  }

  /**
   * Stores information about column types.
   *
   * @private
   * @type {Map<string, XamGridColumnType>}
   * @memberof XamGridModel
   */
  private readonly columnTypes: Map<string, XamGridColumnType> = new Map<
    string,
    XamGridColumnType
  >();
}

// Replaced with class RowCollection
export class XamGridRowCollection<T> extends ObservableCollection<any> {
  private xamGrid: XamGridModel;

  constructor(parentGrid: XamGridModel) {
    super();
    this.xamGrid = parentGrid;
  }

  getItem(index: number): any {
    const row = super.getItem(index);
    return row;
  }

  /**
   * Inserts a new element at the specified position.
   *
   * @param {number} index
   * @param {XamGridRow} value
   * @memberof XamGridRowCollection
   */
  insert(index: number, value: XamGridRow): void {
    super.insert(index, value);
    if (index < 0 || value == null) {
      return;
    }

    const source = this.xamGrid.ItemsSource;
    if (source) {
      this.xamGrid.change.fire(['ItemsSource']);
    }
  }

  /**
   * Removes the first element from the collection which matches the given value.
   *
   * @param {XamGridRow} value
   * @return {boolean}
   * @memberof ObservableCollection
   */
  remove(value: XamGridRow): boolean {
    const result = super.remove(value);
    const source = this.xamGrid.ItemsSource;
    if (value != null && source) {
      const index = -1;
      if (index >= 0) {
        this.xamGrid.change.fire(['ItemsSource']);
      }
    }

    return result;
  }
}

/**
 *  Readonly collection of columns
 *
 * @export
 * @class ReadOnlyKeyedColumnBaseCollection
 * @extends {ObservableCollection<T>}
 * @template T
 * @wType Infragistics.Controls.Grids.ReadOnlyKeyedColumnBaseCollection`1
 */
export class ReadOnlyKeyedColumnBaseCollection<
  T extends XamGridColumnModel
> extends ObservableCollection<T> {
  getColumnByKey(key: string) {
    return findColumn(key, this);
  }
}

/**
 *  Base class for column collections
 *
 * @export
 * @class ColumnBaseCollection
 * @extends {ObservableCollection<XamGridColumnModel>}
 * @wType Infragistics.Controls.Grids.ColumnBaseCollection
 */
export class ColumnBaseCollection extends ObservableCollection<XamGridColumnModel> {
  /**
   * XamGrid ColumnLayout internal reference.
   *
   * @type {ColumnLayout}
   * @memberof ColumnBaseCollection
   */
  private _columnLayout: ColumnLayout;

  /**
   * List of non layout columns.
   *
   * @type {SimpleList<XamGridColumnModel>}
   * @memberof ColumnBaseCollection
   */
  private _nonLayoutColumns: SimpleList<XamGridColumnModel>;

  /**
   * XamGrid DataColumns internal reference.
   *
   * @type {ReadOnlyKeyedColumnBaseCollection<XamGridColumnModel>}
   * @memberof ColumnBaseCollection
   */
  private _dataColumns: ReadOnlyKeyedColumnBaseCollection<XamGridColumnModel>;

  /**
   * XamGrid cached data columns.
   *
   * @type {ColumnLayout}
   * @memberof ColumnBaseCollection
   */
  private _rebuildAllDataColumnsCache: boolean;

  /**
   * Gets XamGrid ColumnLayout reference.
   *
   * @readonly
   * @type {ColumnLayout}
   * @memberof ColumnBaseCollection
   */
  get ColumnLayout(): ColumnLayout {
    return this._columnLayout;
  }

  /**
   * Gets list of non layout columns.
   *
   * @readonly
   * @type {ColumnLayout}
   * @memberof ColumnBaseCollection
   * @wIgnore
   */
  get NonLayoutColumns(): SimpleList<XamGridColumnModel> {
    return this._nonLayoutColumns;
  }

  /**
   * Gets an array of data columns.
   *
   * @readonly
   * @type {ReadOnlyKeyedColumnBaseCollection<XamGridColumnModel>}
   * @memberof ColumnBaseCollection
   */
  get DataColumns(): ReadOnlyKeyedColumnBaseCollection<XamGridColumnModel> {
    return new ReadOnlyKeyedColumnBaseCollection(this.toArray());
  }

  /**
   * Creates an instance of ColumnBaseCollection class
   *
   * @param {ColumnLayout} ColumnLayout
   * @memberof ColumnBaseCollection
   */
  constructor(columnLayout: ColumnLayout) {
    super();
    this._columnLayout = columnLayout;
    this._nonLayoutColumns = new SimpleList<XamGridColumnModel>();
    this._dataColumns = new ReadOnlyKeyedColumnBaseCollection(
      this._nonLayoutColumns
    );
  }

  /**
   * Get a columns by its key.
   *
   * @param {string} key
   * @returns {XamGridColumnModel}
   * @memberof ColumnBaseCollection
   */
  getColumnByKey(key: string): XamGridColumnModel {
    return findColumn(key, this);
  }

  /**
   * Get a columns by its key recursively.
   *
   * @param {string} key
   * @memberof ColumnBaseCollection
   */
  getColumnByKeyDeep(key: string): {
    column: XamGridColumnModel;
    isRoot: boolean;
  } {
    const groupColumns = [];
    for (const column of this) {
      if (column.Key === key) {
        return { column, isRoot: true };
      }
      if (column instanceof XamGridGroupColumnModel) {
        groupColumns.push(column);
      }
    }

    for (const columnGroup of groupColumns) {
      let { column } = columnGroup.Columns.getColumnByKeyDeep(key);
      if (column) {
        return { column, isRoot: false };
      }
    }
    return { column: null, isRoot: false };
  }

  /**
   * Add a new item to the collection.
   *
   * @param {XamGridColumnModel} item
   * @type {void}
   * @memberof ColumnBaseCollection
   */
  AddItem(item: XamGridColumnModel): void {
    this.add(item);
    this.ColumnLayout.OnColumnAdded(item);
  }

  /**
   * Gets an item from the collection.
   *
   * @param {number} index
   * @type {XamGridColumnModel}
   * @memberof ColumnBaseCollection
   */
  getItem(index: number): XamGridColumnModel {
    if (index >= 0 || index < this.count) {
      return super.getItem(index);
    }
  }

  /**
   * Adds columns to the NonLayoutColumns collection.
   *
   * @param {boolean} fullInvalidate
   * @type {XamGridColumnModel}
   * @memberof ColumnBaseCollection
   */
  InvalidateColumnsCollections(fullInvalidate: boolean) {
    this._nonLayoutColumns.clear();
    if (this.ColumnLayout?.Grid) {
      this.internalArray.forEach((ColumnBase) => {
        if (ColumnBase instanceof XamGridColumnModel) {
          this._nonLayoutColumns.add(ColumnBase);
        }
      });
      this._rebuildAllDataColumnsCache = true;
    }
  }

  /**
   * add a new column to the collection.
   *
   * @param {XamGridColumnModel} value
   * @memberof ColumnBaseCollection
   */
  add(value: XamGridColumnModel): void {
    value.ColumnLayout = this.ColumnLayout;
    if (this.ColumnLayout?.Grid?.gridComponentInstance) {
      this.ColumnLayout.Grid.gridComponentInstance.forcedColumnsWidthCalc =
        true;
      this.ColumnLayout.Grid.gridComponentInstance.detectChangesAction?.();
    }
    super.add(value);
  }
}

/**
 *  Event arguments for the `page changed` event
 *
 * @export
 * @class PageChangedEventArgs
 * @wType Infragistics.Controls.Grids.PageChangedEventArgs
 */
export class PageChangedEventArgs {
  /**
   *  The index of the previous page
   *
   * @memberof PageChangedEventArgs
   */
  OldPageIndex = -1;
}

/**
 * Event argument for the "cancellable pagin changing" event
 *
 * @export
 * @class CancellablePageChangingEventArgs
 * @wType Infragistics.Controls.Grids.CancellablePageChangingEventArgs
 */
export class CancellablePageChangingEventArgs extends CancellableEventArgs {
  NextPageIndex = 0;
}

/**
 * Event argument for the "cell clicked" event
 *
 * @export
 * @class CellClickedEventArgs
 * @wType Infragistics.Controls.Grids.CellClickedEventArgs
 */
export class CellClickedEventArgs {
  constructor(protected model: XamGridCell) {}

  /**
   *  Cell being clicked
   *
   * @readonly
   * @type {*}
   * @memberof CellClickedEventArgs
   */
  get Cell(): any {
    return this.model;
  }
}

/**
 * Event arguments for the "Begin Editing Cell" event
 *
 * @export
 * @class BeginEditingCellEventArgs
 * @extends {CancellableEventArgs}
 * @wType Infragistics.Controls.Grids.BeginEditingCellEventArgs
 */
export class BeginEditingCellEventArgs extends CancellableEventArgs {
  constructor(protected model: XamGridCell) {
    super();
  }

  /**
   * Cell being edited
   *
   * @readonly
   * @type {*}
   * @memberof BeginEditingCellEventArgs
   */
  get Cell(): any {
    return this.model;
  }
}

/**
 *  Events object for the "Editing Cell" event arguments
 *
 * @export
 * @class EditingCellEventArgs
 * @wType Infragistics.Controls.Grids.EditingCellEventArgs
 */
export class EditingCellEventArgs extends CancellableEventArgs {
  constructor(protected model: XamGridCell) {
    super();
  }

  // Editor event args.
  #editor: any = null;
  /**
   *  Cell being edited
   *
   * @readonly
   * @type {*}
   * @memberof EditingCellEventArgs
   */
  get Cell(): XamGridCell {
    return this.model;
  }

  /**
   * Editor object
   *
   * @readonly
   * @type {*}
   * @memberof EditingCellEventArgs
   */
  get Editor(): any {
    return this.#editor;
  }

  /**
   * Set Editor property.
   *
   * @memberof EditingCellEventArgs
   */
  set Editor(value: any) {
    this.#editor = value;
  }
}

/**
 *  Base class for event arguments related to row events
 *
 * @export
 * @class RowEventArgs
 * @wType Infragistics.Controls.Grids.RowEventArgs
 */
export class RowEventArgs {
  /**
   * Gets the row property value
   * @wNoMap
   */
  get Row(): any {
    Debugger.Throw('Not implemented');
    return undefined;
  }
}

/**
 * Class used for EditRow Events
 *
 * @export
 * @class EditingRowEventArgs
 * @extends {RowEventArgs}
 * @wType Infragistics.Controls.Grids.EditingRowEventArgs
 */
export class EditingRowEventArgs extends RowEventArgs {
  constructor(row: any) {
    super();
    this.#row = row;
  }
  #row: XamGridRow;
  /**
   * Gets the Row affected by the event
   *
   * @type {*}
   * @memberof EditingRowEventArgs
   */
  get Row(): any {
    return this.#row;
  }
  set Row(value: any) {
    this.#row = value;
  }
}

/**
 *  Event arguments for row initialization
 *
 * @export
 * @class InitializeRowEventArgs
 * @extends {RowEventArgs}
 * @wType Infragistics.Controls.Grids.InitializeRowEventArgs
 */
export class InitializeRowEventArgs extends RowEventArgs {
  constructor(row: any) {
    super();
    this.#row = row;
  }
  #row: XamGridRow;
  /**
   * Gets the Row affected by the event
   *
   * @type {*}
   * @memberof InitializeRowEventArgs
   */
  get Row(): any {
    return this.#row;
  }
  /**
   * Sets the Row affected by the event
   *
   * @type {*}
   * @memberof InitializeRowEventArgs
   */
  set Row(value: any) {
    this.#row = value;
  }
}

/**
 *  Event argument for the "Cell Exited Editing" event
 *
 * @export
 * @class CellExitedEditingEventArgs
 * @wType Infragistics.Controls.Grids.CellExitedEditingEventArgs
 */
export class CellExitedEditingEventArgs {
  constructor(protected model: XamGridCell) {}

  /**
   *  Cell being edited
   *
   * @readonly
   * @type {*}
   * @memberof CellExitedEditingEventArgs
   */
  get Cell(): XamGridCell {
    return this.model;
  }
}

/**
 *  Event arguments for the "Cell Control Attached" event
 *
 * @export
 * @class CellControlAttachedEventArgs
 * @wType Infragistics.Controls.Grids.CellControlAttachedEventArgs
 */
export class CellControlAttachedEventArgs {
  constructor() {}

  /**
   * The cell being added to the grid view
   *
   * @readonly
   * @memberof CellControlAttachedEventArgs
   */
  Cell: XamGridCell;
}

/**
 *  Enumeration for cell selection arguments
 *
 * @export
 * @enum {number}
 * @wEnum Infragistics.Controls.Grids.CellSelectionAction
 */
export enum CellSelectionAction {
  /**
   * Row being selected
   */
  SelectRow,

  /**
   * Cell being selected
   */
  SelectCell,
}

/**
 * An object that contains settings for selection on the XamGrid
 *
 * @export
 * @class SelectionSettings
 * @wType Infragistics.Controls.Grids.SelectionSettings
 */
export class SelectionSettings {
  /**
   * Grid property
   * @wIgnore
   */
  Grid: XamGridModel;

  RowSelection = XamSelectionMode.Single;
  CellSelection = XamSelectionMode.Multiple;
  ColumnSelection = XamSelectionMode.None;
  /**
   * Custom property to handle internal checkbox selection , should be hide as default
   * @wIgnore
   */
  HideRowCheckboxes = true;
  CellClickAction = CellSelectionAction.SelectCell;

  SelectedCells = new ObservableCollection();
  SelectedColumns: ColumnBaseCollection;
  private _selectedRows: SelectedRowsCollection;

  /**
   * Gets or sets the selected rows collection
   *
   * @type {SelectedRowsCollection}
   * @memberof SelectionSettings
   */
  get SelectedRows(): SelectedRowsCollection {
    if (this._selectedRows == null) {
      this._selectedRows = new SelectedRowsCollection();
      this._selectedRows.Grid = this.Grid;
    }
    return this._selectedRows;
  }

  set SelectedRows(value) {
    this._selectedRows = value;
  }

  constructor(columnLayout: ColumnLayout) {
    this.SelectedColumns = new ColumnBaseCollection(columnLayout);
  }
}

/**
 * Enumeration for specifying the paging location
 *
 * @export
 * @enum {number}
 * @wEnum Infragistics.Controls.Grids.PagingLocation
 */
export enum PagingLocation {
  Both,
  Bottom,
  Hidden,
  None,
  Top,
}

/**
 * An object that contains settings for using PagerSettings on the XamGrid
 *
 * @export
 * @class PagerSettings
 * @wType Infragistics.Controls.Grids.PagerSettings
 */
export class PagerSettings extends Control {
  /**
   * AllowPagingProperty dependency property
   *
   * @static
   * @memberof PagerSettings
   */
  static AllowPagingProperty = new DependencyProperty(
    'AllowPaging',
    PagingLocation.None,
    null
  );

  /**
   * CurrentPageIndexProperty dependency property
   *
   * @static
   * @memberof PagerSettings
   * @wIgnore
   */
  static CurrentPageIndexProperty = new DependencyProperty(
    'CurrentPageIndex',
    0,
    null
  );

  /**
   * PageSizeProperty dependency property
   *
   * @static
   * @memberof PagerSettings
   */
  static PageSizeProperty = new DependencyProperty('PageSize', 10, null);
  protected _currentPageIndex = 0;
  protected _pageSize = 10;

  /**
   * Gets/sets if paging will be allowed by default.
   *
   * @type {PagingLocation}
   * @memberof PagerSettings
   */
  @Dependency(PagerSettings.AllowPagingProperty)
  public AllowPaging: PagingLocation;

  /**
   * Gets/sets what page of data will be displayed.
   *
   * @type {number}
   * @memberof PagerSettings
   */
  @Dependency(PagerSettings.CurrentPageIndexProperty)
  public CurrentPageIndex: number;

  /**
   * Gets/sets the maximum number of rows that will be available per page.
   *
   * @type {number}
   * @memberof PagerSettings
   */
  @Dependency(PagerSettings.PageSizeProperty)
  public PageSize: number;
}

/**
 * An object that contains settings for using ColumnResizingSettings on the XamGrid
 *
 * @export
 * @class ColumnResizingSettings
 * @wType Infragistics.Controls.Grids.ColumnResizingSettings
 */
export class ColumnResizingSettings {
  AllowColumnResizing = true;
}

/**
 * An object that contains settings for using ColumnMovingSettings on the XamGrid
 *
 * @export
 * @class ColumnMovingSettings
 * @wType Infragistics.Controls.Grids.ColumnMovingSettings
 */
export class ColumnMovingSettings {
  AllowColumnMoving = false;
}

/**
 * An object that contains settings for using RowSelectorSettings on the XamGrid
 *
 * @export
 * @class RowSelectorSettings
 * @wType Infragistics.Controls.Grids.RowSelectorSettings
 */
export class RowSelectorSettings {
  EnableRowNumbering = true;
}

/**
 * Enumeration for specifying the kind of filtering being used in the grid
 *
 * @export
 * @enum {number}
 * @wEnum Infragistics.Controls.Grids.FilteringScope
 */
export enum FilteringScope {
  ChildBand,
  ColumnLayout,
}

/**
 *  Class to represent the Sorting Settings
 *
 * @export
 * @class SortingSettings
 * @wType Infragistics.Controls.Grids.SortingSettings
 */
export class SortingSettings {
  AllowSorting = true;
  AllowMultipleColumnSorting = true;
  FirstSortDirection = SortDirection.Ascending;
  SortedColumns = new ObservableCollection<XamGridColumnModel>();
}

/**
 *  Interface for record filters
 *
 * @export
 * @interface IRecordFilter
 * @wInterface Infragistics.IRecordFilter
 */
export interface IRecordFilter {
  Conditions: any; // ConditionCollection;
  FieldName: string;
}

/**
 *  Enumeration for editing type
 *
 * @export
 * @enum {number}
 * @wEnum Infragistics.Controls.Grids.EditingType
 */
export enum XamGridEditingType {
  None,
  Cell,
  Row,
  Hover,
}

/**
 *  Enumeration for mouse editing action
 *
 * @export
 * @enum {number}
 * @wEnum Infragistics.Controls.Grids.MouseEditingAction
 */
export enum MouseEditingAction {
  DoubleClick,
  None,
  SingleClick,
}

/**
 * A class to represent the FilteringSettings
 * @export
 * @class RowFiltersCollection
 * @wType Infragistics.Controls.Grids.FilteringSettings
 */
export class FilteringSettings extends Control {
  /**
   * AllowFilteringProperty dependency property
   *
   * @static
   * @memberof FilteringSettings
   */
  static AllowFilteringProperty = new DependencyProperty(
    'AllowFiltering',
    0,
    null
  );

  protected _allowFiltering = FilterUIType.None;

  @Dependency(FilteringSettings.AllowFilteringProperty)
  public AllowFiltering: FilterUIType;

  FilteringScope = FilteringScope.ChildBand;

  RowFiltersCollection = new RowFiltersCollection();

  internalXamGrid: XamGridModel;
}

/**
 * A class to represent the RowFiltersCollection
 * @export
 * @class RowFiltersCollection
 * @wType Infragistics.Controls.Grids.RowFiltersCollection
 */
export class RowFiltersCollection extends ObservableCollection<IRecordFilter> {
  /**
   * Gets rows filter item by key
   *
   * @param {string} key
   * @returns
   * @memberof FilteringSettings
   */
  getItemByKey(key: string): IRecordFilter {
    return this.GetRowFilterByColumnKey(key);
  }

  /**
   * Gets row filter by column key
   *
   * @param {string} columnKey
   * @returns {IRecordFilter}
   * @memberof FilteringSettings
   */
  GetRowFilterByColumnKey(columnKey: string): IRecordFilter {
    for (const recordFilter of this.internalArray) {
      if (recordFilter.FieldName === columnKey) {
        return recordFilter;
      }
    }
    return null;
  }
}

/**
 * A class to represent the grid FixedColumnSettings
 * @export
 * @class EditingSettings
 * @wType Infragistics.Controls.Grids.FixedColumnSettings
 */
export class FixedColumnSettings {
  AllowFixedColumns = false;
  FixedColumnsLeft = new ObservableCollection<XamGridColumnModel>();
  FixedColumnsRight = new ObservableCollection<XamGridColumnModel>();
}

/**
 * A class to represent the grid Editing Settings
 * @export
 * @class EditingSettings
 * @wType Infragistics.Controls.Grids.EditingSettings
 */
export class EditingSettings {
  AllowEditing: XamGridEditingType;
  IsOnCellActiveEditingEnabled = false;
  IsMouseActionEditingEnabled = MouseEditingAction.DoubleClick;
  IsEnterKeyEditingEnabled = false;
  IsF2EditingEnabled = false;
}

/**
 *  Event arguments for the "Editing Cell" event
 *
 * @export
 * @class ExitEditingCellEventArgs
 * @extends {CancellableEventArgs}
 * @wType Infragistics.Controls.Grids.ExitEditingCellEventArgs
 */
export class ExitEditingCellEventArgs extends CancellableEventArgs {
  /**
   * Creates an instance of ExitEditingCellEventArgs.
   * @param {XamGridCell} model
   * @memberof ExitEditingCellEventArgs
   */
  constructor(protected model: XamGridCell) {
    super();
  }

  /**
   * Private reference to the editor instance
   *
   * @type {*}
   * @memberof ExitEditingCellEventArgs
   */
  #editor: any = null;

  /**
   *  Cell being edited
   *
   * @readonly
   * @type {*}
   * @memberof ExitEditingCellEventArgs
   */
  get Cell(): XamGridCell {
    return this.model;
  }

  /**
   *  Editor object
   *
   * @readonly
   * @type {*}
   * @memberof ExitEditingCellEventArgs
   */
  get Editor(): any {
    return this.#editor;
  }

  /**
   * Set Editor property.
   *
   * @memberof ExitEditingCellEventArgs
   */
  set Editor(value: any) {
    this.#editor = value;
  }
}

/**
 *  Enumeration for specifying the kind of filtering UI
 *
 * @export
 * @enum {number}
 * @wEnum Infragistics.Controls.Grids.FilterUIType
 */
export enum FilterUIType {
  None,
  FilterRowTop,
  FilterRowBottom,
  FilterMenu,
}

/**
 * A class to represent grid cells
 *
 * @export
 * @class XamGridCell
 * @wType Infragistics.Controls.Grids.Cell
 */
export class XamGridCell extends CellBase {
  #IsActive = false;
  #IsSelected = false;
  /**
   * @wIgnore
   */
  _style: RuntimeStyleInfo = null;

  /**
   * Key for the cell
   *
   * @type {string}
   * @memberof XamGridCell
   */
  key: string;
  get gridComponent(): any {
    return this.Row.ColumnLayout.Grid?.gridComponentInstance?.grid;
  }

  /**
   * Returns the index of the cell in the grid when is visible in the viewport otherwise returns -1
   *
   * @private
   * @return {*}  {number}
   * @memberof XamGridCell
   */
  private visibleIndex(): number {
    return (
      this.gridComponent.getColumnByName(this.Column?.Key)?.visibleIndex ?? -1
    );
  }

  /**
   * Determines if the editor style was resolved
   *
   * @memberof XamGridCell
   */
  EditorStyleResolved: RuntimeStyleInfo = null;

  /**
   *  Determines if this cell is active
   *
   * @memberof XamGridCell
   */
  get IsActive(): boolean {
    return this.Row.ColumnLayout.Grid.ActiveCell == this;
  }

  /* istanbul ignore next */
  set IsActive(value: boolean) {
    if (value) {
      this.Row.ColumnLayout.Grid.ActiveCell = this;
    } else {
      this.Row.ColumnLayout.Grid.ActiveCell = null;
      this.Row.ColumnLayout.Grid.gridComponentInstance?.cleanActiveFromIgxGrid?.();
    }
  }

  /**
   * Determines if this cell is selected
   *
   * @memberof XamGridCell
   */
  get IsSelected() {
    return this.#IsSelected;
  }

  /* istanbul ignore next */
  set IsSelected(value: boolean) {
    if (value === this.#IsSelected) {
      return;
    }
    this.#IsSelected = value;
    const node = {
      row: this.Row?.Index,
      column: this.gridComponent?.getColumnByName(this.Column?.Key)
        ?.visibleIndex,
    };
    value
      ? this.gridComponent?.selectionService.add(node)
      : this.gridComponent?.grid?.selectionService.remove(node);
  }

  /**
   * Cell style
   *
   * @type {RuntimeStyleInfo}
   * @memberof XamGridCell
   */
  get Style() {
    return this._style;
  }

  set Style(val: RuntimeStyleInfo) {
    if (this._style !== val) {
      this._style = val;
      if (
        this.Column.ColumnLayout.Grid.gridComponentInstance?.cellStyleEnabled
      ) {
        this.Column.ColumnLayout.Grid.gridComponentInstance.cellChanged();
      }
    }
  }

  /**
   *  Cell value
   *
   * @type {unknown}
   * @memberof XamGridCell
   */
  get Value(): any {
    if (this.Row.Data == null) {
      return null;
    }
    if (this.Column.Key == null) {
      return null;
    }
    return this.Row.Data[this.Column.Key];
  }

  /**
   * Creates an instance of XamGridCell.
   * @param {RowBase} [row]
   * @param {XamGridColumnModel} [column]
   * @memberof XamGridCell
   */
  constructor(row?: RowBase, column?: XamGridColumnModel) {
    super();
    this.Row = row;
    this.Column = column;
  }
}

/**
 * An object used to represent the associated control to a cell
 *
 * @export
 * @class XamGridCellControl
 * @extends {ContentControlModel}
 */
export class XamGridCellControl extends ContentControlModel {
  /**
   * Helper property to resolve UnboundDataContext and keep unique reference for comparison
   *
   * @type {UnboundColumnDataContext}
   * @memberof XamGridCellControl
   */
  UnboundDataContextResolver: UnboundColumnDataContext;

  /**
   * Lazy load content setter
   *
   * @type {*}
   * @memberof XamGridCellControl
   */
  set LazyLoadContent(value: any) {
    this.lazyLoadContent = value;
    this.isLazyLoad = value ? true : false;
  }

  /**
   * On demand data context resolve function to recalculate DataContext each request
   *
   * @type {*}
   * @memberof XamGridCellControl
   */
  onDemandLoadDataContext: any;

  /**
   * The columns associated to the control
   *
   * @type {*}
   * @memberof XamGridCellControl
   */
  Column: any = null;

  /**
   * The cell associated to the control
   *
   * @type {*}
   * @memberof XamGridCellControl
   */
  Cell: any = null;

  /**
   * Represents the content of the Content with lazy loading
   *
   * @type {*}
   * @memberof XamGridCellControl
   */
  set Content(value: any) {
    this.setValue(XamGridCellControl.ContentProperty, value);
  }

  get Content(): any {
    if (this.isLazyLoad) {
      this.setValue(XamGridCellControl.ContentProperty, this.lazyLoadContent());
    }
    return this.getValue(XamGridCellControl.ContentProperty);
  }

  /**
   * Sets the datacontext
   *
   * @memberof XamGridCellControl
   */
  set DataContext(value: any) {
    this.setValue(XamGridCellControl.DataContextProperty, value);
  }

  /**
   * Gets the data context updated using firts the onDemandLoadDataContext
   *
   * @type {*}
   * @memberof XamGridCellControl
   */
  get DataContext(): any {
    this.refreshDataContext();
    return this.getValue(XamGridCellControl.DataContextProperty);
  }

  /**
   * Lazy load content function
   *
   * @type {*}
   * @private
   * @memberof XamGridCellControl
   */
  private lazyLoadContent: any;

  /**
   * Flag to set the content when lazy loading
   *
   * @type {boolean}
   * @private
   * @memberof XamGridCellControl
   */
  private isLazyLoad = false;

  /**
   * Refresh data context is used to be triggered internally and from child to force the XamGridCell to update
   * the DataContext
   *
   * @memberof XamGridCellControl
   */
  refreshDataContext(): void {
    if (this.onDemandLoadDataContext) {
      this.setValue(
        XamGridCellControl.DataContextProperty,
        this.onDemandLoadDataContext()
      );
    }
  }

  /**
   * Overrides the ContentChangeHandler for lazy loading initialization
   *
   * @param {DependencyPropertyChangedEventArgs} args
   * @memberof XamGridCellControl
   */
  public ContentChangeHandler(args: DependencyPropertyChangedEventArgs) {
    super.ContentChangeHandler(args);
  }
}

/**
 * An object used by the UnboundColumn to hold the DataContext for an unbound cell.
 *
 * @export
 * @class UnboundColumnDataContext
 * @wType Infragistics.Controls.Grids.UnboundColumnDataContext
 */
export class UnboundColumnDataContext implements INotifyPropertyChanged {
  /**
   * Event to indicate that a property have changed.
   *
   * @memberof UnboundColumnDataContext
   */
  public PropertyChanged: SubscriptionEvent<
    (e: any, args: { PropertyName: string }) => void
  > = new SubscriptionEvent();

  private columnKey: string;
  private rowData: any;
  private value: any;
  private valueConverter: IValueConverter;

  /**
   * The column key of the associate Column
   *
   * @memberof UnboundColumnDataContext
   */
  public get ColumnKey() {
    return this.columnKey;
  }

  public set ColumnKey(value: string) {
    this.columnKey = value;
    this.onPropertyChanged({ PropertyName: 'ColumnKey' });
  }

  /**
   * The data object associated with the row of data
   *
   * @memberof UnboundColumnDataContext
   */
  public get RowData() {
    return this.rowData;
  }

  public set RowData(value: any) {
    this.rowData = value;
    this.onPropertyChanged({ PropertyName: 'RowData' });
  }

  /**
   * The value generated by the ValueConverter.
   *
   * @memberof UnboundColumnDataContext
   */
  public get Value() {
    return this.valueConverter
      ? this.valueConverter.Convert(this.value, null, null, null)
      : this.value;
  }

  public set Value(value: any) {
    this.value = value;
    this.onPropertyChanged({ PropertyName: 'Value' });
  }

  /**
   * Creates an instance of UnboundColumnDataContext.
   *
   * @param {string} columnKey
   * @param {*} rowData
   * @param {*} value
   * @param {IValueConverter} [converter]
   * @memberof UnboundColumnDataContext
   */
  constructor(
    columnKey: string,
    rowData: any,
    value: any,
    converter?: IValueConverter
  ) {
    this.columnKey = columnKey;
    this.rowData = rowData;
    this.value = value;
    this.valueConverter = converter;
  }

  /**
   * Raises the PropertyChanged event
   *
   * @protected
   * @param {{ PropertyName: string }} info
   * @memberof UnboundColumnDataContext
   * @wMethod OnPropertyChanged
   */
  /* istanbul ignore next */
  protected onPropertyChanged(info: { PropertyName: string }): void {
    this.PropertyChanged.fire([this, info]);
  }
}

/**
 *  Collection for selected rows
 *
 * @export
 * @class SelectedRowsCollection
 * @extends {ObservableCollection<XamGridRow>}
 * @wType Infragistics.Controls.Grids.SelectedRowsCollection
 */
export class SelectedRowsCollection extends ObservableCollection<XamGridRow> {
  /**
   * Property to keep the xamGrid reference
   *
   * @type {XamGridModel}
   * @memberof SelectedRowsCollection
   * @wIgnore
   */
  Grid: XamGridModel;

  /**
   * Creates an instance of SelectedRowsCollection.
   * @param {Iterable<XamGridRow>} [initial]
   * @memberof SelectedRowsCollection
   */
  constructor(initial?: Iterable<XamGridRow>) {
    super(initial);
  }

  /**
   * Remove the row from the collection and
   * set in false the selection property of the row
   *
   * @param {XamGridRow} value
   * @return {*}  {boolean}
   * @memberof SelectedRowsCollection
   */
  remove(value: XamGridRow): boolean {
    value.SetSelected(false);
    const newEventArgs =
      new SelectionCollectionChangedEventArgs<SelectedRowsCollection>();
    newEventArgs.NewSelectedItems = new SelectedRowsCollection();
    newEventArgs.PreviouslySelectedItems = new SelectedRowsCollection(
      this.toArray()
    );
    const result = super.remove(value);
    this.gridTriggerChange(newEventArgs);
    return result;
  }

  /**
   * Remove the row from the collection by Index and
   * set in false the selection property of the row
   * @param {number} index
   * @memberof SelectedRowsCollection
   */
  removeAt(index: number): void {
    this.getItem(index).SetSelected(false);
    const newEventArgs =
      new SelectionCollectionChangedEventArgs<SelectedRowsCollection>();
    newEventArgs.NewSelectedItems = new SelectedRowsCollection();
    newEventArgs.PreviouslySelectedItems = new SelectedRowsCollection(
      this.toArray()
    );
    super.removeAt(index);
    this.gridTriggerChange(newEventArgs);
  }

  /**
   * If the grid is not null, fire the change event on the grid for the SelectedItem.
   * The change event is a built-in event that is fired whenever the grid's data changes.
   * @memberof SelectedRowsCollection
   */
  private gridTriggerChange(
    eventArgs?: SelectionCollectionChangedEventArgs<SelectedRowsCollection>
  ): void {
    if (eventArgs) {
      this.Grid?.SelectedRowsCollectionChanged.fire([this.Grid, eventArgs]);
    }
    this.Grid?.change.fire(['SelectedRowsChanged']);
  }

  /**
   * Remove all the rows from the collection and
   * set in false the selection property of each row
   * @memberof SelectedRowsCollection
   */
  clear(): void {
    this.forEach((item) => item.SetSelected(false));
    let newEventArgs = null;
    if (this.count > 0) {
      newEventArgs =
        new SelectionCollectionChangedEventArgs<SelectedRowsCollection>();
      newEventArgs.NewSelectedItems = new SelectedRowsCollection();
      newEventArgs.PreviouslySelectedItems = new SelectedRowsCollection(
        this.toArray()
      );
    }
    super.clear();
    this.gridTriggerChange(newEventArgs);
  }

  /**
   * Add the row to the collection and
   * set in true the selection property of the row
   * @param {XamGridRow} value
   * @memberof SelectedRowsCollection
   */
  add(value: XamGridRow): void {
    value.SetSelected(true);
    const newEventArgs =
      new SelectionCollectionChangedEventArgs<SelectedRowsCollection>();
    newEventArgs.NewSelectedItems = new SelectedRowsCollection([value]);
    newEventArgs.PreviouslySelectedItems = new SelectedRowsCollection(
      this.toArray()
    );
    super.add(value);
    this.gridTriggerChange(newEventArgs);
  }

  /**
   * Add the rows to the collection by index and
   * set in true the selection property of each row
   * @param {Iterable<XamGridRow>} values
   * @memberof SelectedRowsCollection
   */
  addRange(values: Iterable<XamGridRow>): void {
    const newEventArgs =
      new SelectionCollectionChangedEventArgs<SelectedRowsCollection>();
    newEventArgs.NewSelectedItems = new SelectedRowsCollection([...values]);
    newEventArgs.PreviouslySelectedItems = new SelectedRowsCollection(
      this.toArray()
    );
    super.addRange(values);
    this.forEach((item) => item.SetSelected(true));
    this.gridTriggerChange(newEventArgs);
  }
}

/**
 *  Event arguments for changed in the selection collection
 *
 * @export
 * @class SelectionCollectionChangedEventArgs
 * @template T
 * @wType Infragistics.Controls.Grids.SelectionCollectionChangedEventArgs`1
 */
export class SelectionCollectionChangedEventArgs<T> {
  NewSelectedItems: T;
  PreviouslySelectedItems: T;
}

/**
 *  Event arguments for column resizing (cancellable)
 *
 * @export
 * @class CancellableColumnResizingEventArgs
 * @extends {CancellableEventArgs}
 * @wType Infragistics.Controls.Grids.CancellableColumnResizingEventArgs
 */
export class CancellableColumnResizingEventArgs extends CancellableEventArgs {}

/**
 * Find the column by key
 *
 * @param {string} key The key of the column to find
 * @param {*} data The data to search in
 * @return {*}  {XamGridColumnModel} The column found
 */
function findColumn(key: string, data): XamGridColumnModel {
  for (const column of data) {
    if (column.Key === key) {
      return column;
    }
  }
  return null;
}

result-matching ""

    No results matching ""