projects/wms-framework/src/lib/models/controls/RowsManager.ts
A class representing the column layout model.
Properties |
|
Methods |
Accessors |
constructor(level: number, columnLayout: ColumnLayout, parentLayoutRow: any)
|
||||||||||||
Creates a new instance of RowsManager
Parameters :
|
Private _addNewRowBottom |
Type : any
|
Internal reference to the newly bottom top row |
Private _addNewRowTop |
Type : AddNewRow
|
Internal reference to the newly added top row |
Private _cachedRows |
Type : any
|
Cached collection of rows to avoid unnecesary functions executions. |
Public _items |
Type : XamGridRow[]
|
Internal items collection. |
Public _itemsSource |
Type : any
|
Internal itemsSource collection |
Private _rowBaseCollection |
Type : RowBaseCollection
|
Internal RowBaseCollection. |
Private _rows |
Type : any
|
Internal rows collection. |
DataManager |
Type : any
|
DataManager |
Public Level |
Type : number
|
Level property |
Public ParentRow |
Type : any
|
Reference to the parent row. |
Protected _columnLayout |
Type : ColumnLayout
|
Inherited from
RowsManagerBase
|
Defined in
RowsManagerBase:32
|
Internal ColumnLayout. |
add | ||||||
add(item: any)
|
||||||
Creates a new item.
Parameters :
Returns :
void
|
AddItem | ||||||
AddItem(addedObject: XamGridRow)
|
||||||
Adds new node to the collection
Parameters :
Returns :
void
|
Clear |
Clear()
|
Clears items.
Returns :
void
|
CreateItem |
CreateItem()
|
Creates a new item.
Returns :
XamGridRow
|
CreateItem | ||||||
CreateItem(dataItem: any)
|
||||||
Parameters :
Returns :
XamGridRow
|
CreateItem | ||||||
CreateItem(dataItem?: any)
|
||||||
Parameters :
Returns :
XamGridRow
|
Private fireItemsSourceChangeIfNotObservable | ||||||
fireItemsSourceChangeIfNotObservable(data: Iterable<any>)
|
||||||
Explicitly fires a ColumnLayout change
Parameters :
Returns :
void
|
GetDataItem |
GetDataItem(index: number, data: any)
|
Gets the row by index and stores the row in the cache
Returns :
XamGridRow
|
getInternalData |
getInternalData()
|
Gets the data to be used to populate the Rows information
Returns :
any
|
GetRecord |
GetRecord(index: number, data: any)
|
Gets the record by index using the given data or retrieve the data from the grid
Returns :
any
|
getValueFromItemsSource | ||||||
getValueFromItemsSource(index: number)
|
||||||
Gets the value from the ItemSource based on its index
Parameters :
Returns :
any
|
hasSortOrFilter |
hasSortOrFilter()
|
Indicates if the grid has filters or sorted columns
Returns :
boolean
|
InsertItem | |||||||||
InsertItem(index: number, insertedObject: XamGridRow)
|
|||||||||
Inserts a new Item into the collection in the given index.
Parameters :
Returns :
void
|
InvalidateData |
InvalidateData()
|
Clears data
Returns :
void
|
InvalidateRows | ||||||
InvalidateRows(unregister: boolean)
|
||||||
Clears rows
Parameters :
Returns :
void
|
OnItemsSourceChanged | ||||||
OnItemsSourceChanged(invalidateSelectionAndActivation: boolean)
|
||||||
Callback function when the ItemsSource have changed
Parameters :
Returns :
void
|
RemoveItem | ||||||
RemoveItem(removedObject: XamGridRow)
|
||||||
Remove the given node of the collection
Parameters :
Returns :
boolean
|
RemoveRange | ||||||
RemoveRange(itemsToRemove: IList<XamGridRow>)
|
||||||
Remove the given list of items to remove
Parameters :
Returns :
void
|
toArray |
toArray()
|
Convert the XamGridRowCollection to a simple array.
Returns :
any[]
|
UnhookDataManager | ||||||||||||
UnhookDataManager(clearChildRows: boolean, clearSelection: boolean, clearGroupBy: boolean)
|
||||||||||||
Refresh data manager property
Parameters :
Returns :
void
|
AddNewRowBottom |
getAddNewRowBottom()
|
Property to keep the add new row at the bottom reference
Returns :
AddNewRow
|
AddNewRowTop |
getAddNewRowTop()
|
Property to keep the add new row at the top reference
Returns :
AddNewRow
|
Rows |
getRows()
|
Gets rows collection
Returns :
RowBaseCollection
|
ItemsSource | ||||||
getItemsSource()
|
||||||
Gets the ItemSource property
Returns :
Iterable<any>
|
||||||
setItemsSource(value: Iterable<any>)
|
||||||
Sets the ItemSource property
Parameters :
Returns :
void
|
DataCount |
getDataCount()
|
Gets the length of the data collection
Returns :
number
|
import { ColumnLayout } from './ColumnLayout';
import { RowBaseCollection } from './RowBaseCollection';
import { RowCollection } from './RowCollection';
import { RowsManagerBase } from './RowsManagerBase';
import { IProvideDataItems } from './IProvideDataItems';
import { AddNewRow } from './AddNewRow';
import { XamGridRow } from './XamGridRow';
import { IList } from '../../baseframework/collections';
/**
* A class representing the column layout model.
*
* @export
* @class RowsManager
* @extends RowsManagerBase
* @implements IProvideDataItems<XamGridRow>
* @wType Infragistics.Controls.Grids.RowsManager
*/
export class RowsManager
extends RowsManagerBase
implements IProvideDataItems<XamGridRow>
{
/**
* Internal reference to the newly added top row
*
* @readonly
* @type {any}
* @memberof RowsManager
*/
private _addNewRowTop: AddNewRow;
/**
* Internal reference to the newly bottom top row
*
* @private
* @type {any}
* @memberof RowsManager
*/
private _addNewRowBottom: any;
/**
* Property to keep the add new row at the bottom reference
*
* @readonly
* @type {AddNewRow}
* @memberof RowsManager
*/
get AddNewRowBottom(): AddNewRow {
if (this._addNewRowBottom == null) {
this._addNewRowBottom = new AddNewRow(this);
// We initialize the Data property because we don't have a way to know the data type
// in Silverlight they get the data type from the data source
this._addNewRowBottom.Data = {};
}
return this._addNewRowBottom;
}
/**
* Property to keep the add new row at the top reference
*
* @readonly
* @type {AddNewRow}
* @memberof RowsManager
*/
get AddNewRowTop(): AddNewRow {
if (this._addNewRowTop == null) {
this._addNewRowTop = new AddNewRow(this);
// We initialize the Data property because we don't have a way to know the data type,
// in Silverlight they get the data type from the data source
this._addNewRowTop.Data = {};
}
return this._addNewRowTop;
}
/**
* DataManager
*
* @type {any}
* @memberof RowsManager
*/
DataManager: any;
/**
* Callback function when the ItemsSource have changed
*
* @param {boolean} invalidateSelectionAndActivation
* @type {void}
* @memberof RowsManager
*/
OnItemsSourceChanged(invalidateSelectionAndActivation: boolean): void {
let grid = this.ColumnLayout.Grid;
if (grid != null) {
grid.ActiveCell = null;
grid.RowsManager.ColumnLayout.Grid.gridComponentInstance?.cleanActiveFromIgxGrid?.();
}
grid.SelectionSettings.SelectedCells.clear();
grid.SelectionSettings.SelectedColumns.clear();
grid.SelectionSettings.SelectedRows.clear();
this.UnhookDataManager(true, true, false);
this.InvalidateRows(true);
this.InvalidateData();
}
/**
* Refresh data manager property
*
* @param {boolean} clearChildRows
* @param {boolean} clearSelection
* @param {boolean} clearGroupBy
* @type {void}
* @memberof RowsManager
* @wIgnore
*/
UnhookDataManager(
clearChildRows: boolean,
clearSelection: boolean,
clearGroupBy: boolean
): void {
if (clearChildRows) {
this._cachedRows.clear();
}
}
/**
* Clears data
*
* @type {void}
* @memberof RowsManager
* @wNoMap
*/
InvalidateData(): void {}
/**
* Clears rows
*
* @type {void}
* @memberof RowsManager
*/
InvalidateRows(unregister: boolean): void {
if (unregister) {
this.Rows.Clear();
this._cachedRows.clear();
}
}
/**
* Internal itemsSource collection
*
* @type {any}
* @memberof RowsManager
*/
public _itemsSource: any;
/**
* Level property
*
* @type {number}
* @memberof RowsManager
*/
public Level: number;
/**
* Reference to the parent row.
*
* @type {XamGridRow[]}
* @memberof RowsManager
*/
public ParentRow: any;
/**
* Internal items collection.
*
* @type {XamGridRow[]}
* @memberof RowsManager
*/
public _items: XamGridRow[];
/**
* Internal RowBaseCollection.
*
* @type {RowBaseCollection}
* @memberof RowsManager
*/
private _rowBaseCollection: RowBaseCollection;
/**
* Internal rows collection.
*
* @type {any}
* @memberof RowsManager
*/
private _rows: any; //RowCollection;
/**
* Cached collection of rows to avoid unnecesary functions executions.
*
* @type {any}
* @memberof RowsManager
*/
private _cachedRows: any;
/**
* Creates a new instance of RowsManager
*
* @param {number} level
* @param {ColumnLayout} columnLayout
* @param {any} parentLayoutRow
* @memberof RowsManager
*/
constructor(level: number, columnLayout: ColumnLayout, parentLayoutRow: any) {
super(columnLayout);
this.Level = level;
this.ParentRow = parentLayoutRow;
this._cachedRows = new Map<object, XamGridRow>();
this._rows = new RowCollection(this, columnLayout);
}
/**
* Creates a new item.
*
* @type {void}
* @memberof RowsManager
* @wIgnore
*/
add(item: any): void {
const data = this.ColumnLayout.Grid.ItemsSource as any;
if (data.add) {
data.add(item.Data);
}
}
/**
* Clears items.
*
* @type {void}
* @memberof RowsManager
* @wIgnore
*/
Clear(): void {
this._items = null;
}
/**
* Creates a new item.
*
* @type {XamGridRow}
* @memberof RowsManager
* @wIgnore
*/
CreateItem(): XamGridRow;
CreateItem(dataItem: any): XamGridRow;
CreateItem(dataItem?: any): XamGridRow {
throw new Error('Method not implemented.');
}
/**
* Adds new node to the collection
*
* @param {XamGridRow} addedObject
* @type {void}
* @memberof RowsManager
*/
AddItem(addedObject: XamGridRow): void {
throw new Error('Method not implemented.');
}
/**
* Remove the given node of the collection
*
* @param {XamGridRow} removedObject
* @type {void}
* @memberof RowsManager
*/
RemoveItem(removedObject: XamGridRow): boolean {
const data = this.ColumnLayout.Grid.ItemsSource as any;
if (data?.remove) {
// Attach data to XamGridRow before removing.
const rowData = removedObject.Data;
removedObject.onDemandData = () => rowData;
data.remove(removedObject.Data);
this._cachedRows?.delete(removedObject.Data);
this.fireItemsSourceChangeIfNotObservable(data);
}
return false;
}
/**
* Remove the given list of items to remove
*
* @param {IList<XamGridRow>} itemsToRemove
* @type {void}
* @memberof RowsManager
*/
RemoveRange(itemsToRemove: IList<XamGridRow>): void {
throw new Error('Method not implemented.');
}
/**
* Inserts a new Item into the collection in the given index.
*
* @param {number} index
* @param {XamGridRow} insertedObject
* @type {void}
* @memberof RowsManager
*/
InsertItem(index: number, insertedObject: XamGridRow): void {
const data = this.ColumnLayout.Grid.ItemsSource as any;
if (data.insert) {
data.insert(index, insertedObject.Data);
// Reset onDemandData behavior in case insertedObject was a previosly removed row.
insertedObject.onDemandData = () =>
this.GetRecord(insertedObject.Index)['data'];
this.fireItemsSourceChangeIfNotObservable(data);
}
}
/**
* Gets rows collection
*
* @readonly
* @type {RowBaseCollection}
* @memberof RowsManager
*/
get Rows(): RowBaseCollection {
if (this._rowBaseCollection == null) {
this._rowBaseCollection = new RowBaseCollection(this._rows);
}
return this._rowBaseCollection;
}
/**
* Gets the ItemSource property
*
* @type {Iterable<any>}
* @memberof RowsManager
*/
get ItemsSource(): Iterable<any> {
return this._itemsSource;
}
/**
* Sets the ItemSource property
*
* @type {Iterable<any>}
* @memberof RowsManager
*/
set ItemsSource(value: Iterable<any>) {
if (this._itemsSource === value) {
return;
}
this._itemsSource = value;
this.OnItemsSourceChanged(this.ParentRow == null);
}
/**
* Gets the row by index and stores the row in the cache
*
* @param {number} index
* @param {*} [data=null]
* @returns {XamGridRow}
* @memberof RowsManager
*/
GetDataItem(index: number, data: any = null): XamGridRow {
if (this._itemsSource == null) {
return null;
}
const record = this.GetRecord(index, data);
if (record) {
const recordData = record['data'];
if (this._cachedRows.has(recordData)) {
const row = this._cachedRows.get(recordData);
row.Index = index;
// using onDemandData mechanism to recalculate the data each time to have the latest value when a index is updated or data change
row.onDemandData = () => this.GetRecord(row.Index)?.['data'];
return row;
} else {
const row = new XamGridRow(index, this, null);
// using onDemandData mechanism to recalculate the data each time to have the latest value when a index is updated or data change
row.onDemandData = () => this.GetRecord(row.Index)?.['data'];
this._cachedRows.set(recordData, row);
return row;
}
}
return null;
}
/**
* Gets the record by index using the given data or retrieve the data from the grid
*
* @param {number} index
* @param {*} [data=null]
* @returns {*}
* @memberof RowsManager
* @wIgnore
*/
GetRecord(index: number, data: any = null): any {
data = data ?? this.getInternalData();
return data.length > 0 && data.length > index ? data[index] : null;
}
/**
* Gets the data to be used to populate the Rows information
*
* @returns {*}
* @memberof RowsManager
*/
getInternalData(): any {
const grid = this.ColumnLayout.Grid.gridComponentInstance?.grid;
if (!grid) {
return [];
}
return grid.filteredSortedData && this.hasSortOrFilter()
? grid.filteredSortedData
: grid.data;
}
/**
* Indicates if the grid has filters or sorted columns
*
* @returns
* @memberof RowsManager
*/
hasSortOrFilter(): boolean {
const gridModel = this.ColumnLayout.Grid;
return (
gridModel.SortingSettings.SortedColumns.count > 0 ||
gridModel.FilteringSettings.RowFiltersCollection.count > 0
);
}
/**
* Gets the value from the ItemSource based on its index
*
* @returns {any}
* @memberof RowsManager
*/
getValueFromItemsSource(index: number): any {
if (this._itemsSource == null) {
return null;
}
if (this._itemsSource.getItem != null) {
return this._itemsSource.getItem(index);
} else {
return this._itemsSource[index];
}
}
/**
* Convert the XamGridRowCollection to a simple array.
*
* @returns {any[]}
* @memberof RowsManager
*/
toArray(): any[] {
if (this._itemsSource == null) {
return [];
}
if (this._items) {
return this._items;
}
const data = this.getInternalData();
if (data) {
this._items = [];
let index = 0;
for (index; index < data.length; index++) {
this._items.push(this.GetDataItem(index, data));
}
return this._items;
}
}
/**
* Gets the length of the data collection
*
* @readonly
* @returns {number}
* @memberof RowsManager
*/
get DataCount(): number {
const data = this.getInternalData();
if (data == null) {
return 0;
}
if (data.count != null) {
return data.count;
}
if (data.length != null) {
return data.length;
}
return 0;
}
/**
* Explicitly fires a ColumnLayout change
*
* @private
* @memberof RowsManager
*/
private fireItemsSourceChangeIfNotObservable(data: Iterable<any>): void {
if (!(data as any).NotifyCollectionChanged) {
this.ColumnLayout.Grid.change.fire(['ItemsSource']);
}
}
}