File

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

Description

Collection of CellBase for the xamGrid

Extends

ObservableCollection

Index

Properties
Methods

Constructor

constructor(columns: any, row: any)

Creates an instance of CellBaseCollection.

Parameters :
Name Type Optional
columns any No
row any No

Properties

Private _auxColumns
Type : Map<XamGridColumnBaseModel | CellBase>

Auxiliar collection of columns

Private _columns
Type : ColumnBaseCollection

private collection of columns

Private _row
Type : any

private collection of rows

Public AddNewItem
Type : SubscriptionEvent<void>
Default value : new SubscriptionEvent()
Inherited from ObservableCollection

Event AddNewItem have changed.

Public CollectionChanged
Type : SubscriptionEvent<void>
Default value : new SubscriptionEvent()
Inherited from ObservableCollection

Event to indicate that the collection have changed.

Protected Static interfacesInitialized
Default value : false
Inherited from SimpleList
Defined in SimpleList:862

Flag to indicate if supported interfaces have been initialized.

Public PropertyChanged
Type : SubscriptionEvent<void>
Default value : new SubscriptionEvent()
Inherited from ObservableCollection

Event to indicate that a property have changed.

Protected _internalArray
Type : T[]
Default value : []
Inherited from SimpleList
Defined in SimpleList:276

Methods

getCellByKey
getCellByKey(keyColumn: string | XamGridColumnModel)

Method to returns the Cell with a specify key

Parameters :
Name Type Optional
keyColumn string | XamGridColumnModel No
Returns : any
getColumnFromDictionary
getColumnFromDictionary(column: XamGridColumnModel)

Gets an item from the collection by its index.

Parameters :
Name Type Optional
column XamGridColumnModel No
Returns : any
getItem
getItem(index: number)
Inherited from SimpleList
Defined in SimpleList:102

Gets an item from the collection by its index.

Parameters :
Name Type Optional
index number No
Returns : any
getKey
getKey(item: any)

Gets the key from an item.

Parameters :
Name Type Optional
item any No
Returns : string | null
registerCellFromUI
registerCellFromUI(item: any, row: RowBase, Columns: ColumnBaseCollection)

Register a new cell that comes from the UI.

Parameters :
Name Type Optional
item any No
row RowBase No
Columns ColumnBaseCollection No
Returns : CellBase
add
add(value: T)
Inherited from SimpleList
Defined in SimpleList:995

Adds the given element at the end of the collection.

Parameters :
Name Type Optional
value T No
Returns : void
clear
clear()
Inherited from SimpleList
Defined in SimpleList:1031

Removes all elements from the collection.

Returns : void
Protected clearItems
clearItems()
Inherited from ObservableCollection

Removes all elements from the collection.

Returns : void
Protected Static initializeSupportedInterfaces
initializeSupportedInterfaces()
Inherited from SimpleList
Defined in SimpleList:913

Initialize the interfaces supported by this collection.

Returns : void
insert
insert(index: number, value: T)
Inherited from SimpleList
Defined in SimpleList:937

Inserts a new element at the specified position.

Parameters :
Name Type Optional
index number No
value T No
Returns : void
Protected onCollectionChanged
onCollectionChanged(info: CollectionChangeInfo)
Inherited from ObservableCollection

Trigger a CollectionChanged event.

Parameters :
Name Type Optional
info CollectionChangeInfo No
Returns : void
Protected onPropertyChanged
onPropertyChanged(info: literal type)
Inherited from ObservableCollection

Trigger a PropertyChanged event.

Parameters :
Name Type Optional
info literal type No
Returns : void
remove
remove(value: T)
Inherited from SimpleList
Defined in SimpleList:955

Removes the first element from the collection which matches the given value.

Parameters :
Name Type Optional
value T No
Returns : boolean

{boolean}

removeAt
removeAt(index: number)
Inherited from SimpleList
Defined in SimpleList:977

Removes the element at the given position.

Parameters :
Name Type Optional
index number No
Returns : void
setItem
setItem(index: number, value: T)
Inherited from SimpleList
Defined in SimpleList:1047

Replace the element at the given position with the given element.

Parameters :
Name Type Optional
index number No
value T No
Returns : void
silentAddRange
silentAddRange(range: Iterable<T>)
Inherited from ObservableCollection

Adds elements of an iterable to the list

Parameters :
Name Type Optional
range Iterable<T> No
Returns : void
addRange
addRange(range: Iterable<T>)
Inherited from SimpleList
Defined in SimpleList:452

Adds elements of an iterable to the list

Parameters :
Name Type Optional
range Iterable<T> No
Returns : void
contains
contains(value: T)
Inherited from SimpleList
Defined in SimpleList:410

Check if a value is contained in the list

Parameters :
Name Type Optional
value T No
Returns : boolean
copyTo
copyTo(target: T[], index: number)
Inherited from SimpleList
Defined in SimpleList:513

Copies the list to a target array

Parameters :
Name Type Optional
target T[] No
index number No
Returns : void
forEach
forEach(action: (e: T) => void)
Inherited from SimpleList
Defined in SimpleList:439

Performs an action on each element of the list

Parameters :
Name Type Optional
action function No
Returns : void
indexOf
indexOf(value: T)
Inherited from SimpleList
Defined in SimpleList:343

Index of value in list

Parameters :
Name Type Optional
value T No
Returns : any
insertRange
insertRange(position: number, range: Iterable<T>)
Inherited from SimpleList
Defined in SimpleList:466

Inserts elements of an interable to the list in a position

Parameters :
Name Type Optional
position number No
range Iterable<T> No
Returns : void
Public removeAll
removeAll(predicate: (e: T) => void)
Inherited from SimpleList
Defined in SimpleList:527

Removes all elements from the collection by a predicate

Parameters :
Name Type Optional
predicate function No
Returns : number
sort
sort()
Inherited from SimpleList
Defined in SimpleList:479

Sorts the list

Returns : any
Public toArray
toArray()
Inherited from SimpleList
Defined in SimpleList:545

Converts the list to an array

Returns : {}
()
Inherited from SimpleList
Defined in SimpleList:549
Returns : Iterator<T, any, undefined>
import {
  XamGridColumnBaseModel,
  XamGridColumnModel,
} from './XamGridColumnModel';
import { CellBase } from './CellBase';
import { ColumnBaseCollection, XamGridCell } from './XamGridModel';
import { RowBase } from './RowBase';
import { ObservableCollection } from '../../baseframework/collections';

/**
 * Collection of CellBase for the xamGrid
 *
 * @export
 * @class CellBaseCollectionModel
 * @extends {ObservableCollection<XamGridCell>}
 * @wType Infragistics.Controls.Grids.Primitives.CellBaseCollection
 */
export class CellBaseCollectionModel extends ObservableCollection<CellBase> {
  /**
   * private collection of rows
   *
   * @private
   * @type {*}
   * @memberof CellBaseCollectionModel
   */
  private _row: any;

  /**
   * private collection of columns
   *
   * @private
   * @type {ColumnBaseCollection}
   * @memberof CellBaseCollectionModel
   */
  private _columns: ColumnBaseCollection;

  /**
   * Auxiliar collection of columns
   *
   * @private
   * @type {Map<XamGridColumnBaseModel, CellBase>}
   * @memberof CellBaseCollectionModel
   */
  private _auxColumns: Map<XamGridColumnBaseModel, CellBase>;

  /**
   * Creates an instance of CellBaseCollection.
   * @param {*} columns
   * @param {*} row
   * @memberof CellBaseCollectionModel
   */
  constructor(columns: any, row: any) {
    super();
    this._row = row;
    this._columns = columns;
    this._auxColumns = new Map<XamGridColumnBaseModel, CellBase>();
  }

  /**
   * Method to returns the Cell with a specify key
   *
   * @param {string} keyColumn
   * @return {*}
   * @memberof GroupColumnsCollection
   */
  getCellByKey(keyColumn: string | XamGridColumnModel): any {
    let column = keyColumn;
    if (typeof column === 'string') {
      let { column: columnTmp } = this._columns.getColumnByKeyDeep(column);
      column = columnTmp;
    }
    if (column instanceof XamGridColumnModel) {
      return this.getColumnFromDictionary(column);
    }
    return null;
  }

  /**
   * Gets an item from the collection by its index.
   *
   * @param {number} index
   * @type {any}
   * @memberof CellBaseCollectionModel
   * @wMethod GetItem
   */
  getItem(index: number): any {
    const column = this._columns.DataColumns.getItem(index);
    return this.getCellByKey(column);
  }

  /**
   * Gets an item from the collection by its index.
   *
   * @param {XamGridColumnModel} column
   * @type {any}
   * @memberof CellBaseCollectionModel
   */
  getColumnFromDictionary(column: XamGridColumnModel): any {
    if (this._auxColumns.has(column)) {
      return this._auxColumns.get(column);
    }
    const cellBase = column.GenerateCell(this._row);
    this.add(cellBase);
    this._auxColumns.set(column, cellBase);
    return cellBase;
  }

  /**
   * Register a new cell that comes from the UI.
   *
   * @param {any} item
   * @param {RowBase} row
   * @param {ColumnBaseCollection} Columns
   * @type {CellBase}
   * @memberof CellBaseCollectionModel
   */
  registerCellFromUI(
    item: any,
    row: RowBase,
    Columns: ColumnBaseCollection
  ): CellBase {
    const key = this.getKey(item);
    const { column, isRoot } = Columns.getColumnByKeyDeep(key);
    if (column) {
      if (this._auxColumns.has(column)) {
        return this._auxColumns.get(column);
      }
      const currentCell = row.Cells.getCellByKey(key);
      if (currentCell) {
        this._auxColumns.set(column, currentCell);
        if (isRoot) {
          this.add(currentCell);
        }
        return currentCell;
      }
      const cell = new XamGridCell(row, column);
      this._auxColumns.set(column, cell);
      if (isRoot) {
        this.add(cell);
      }
      return cell;
    }
    console.log('this is not a valid column');
  }

  /**
   * Gets the key from an item.
   *
   * @param {any} item
   * @type {string | null}
   * @memberof CellBaseCollectionModel
   */
  getKey(item: any): string | null {
    let columnString = '';
    if (item.column?.field) {
      columnString = item.column?.field;
    } else if (item._columnField) {
      columnString = item._columnField;
    }
    const key = columnString.substring(5, columnString.length);
    return key ?? '';
  }
}

result-matching ""

    No results matching ""