Skip to content

Commit

Permalink
feat(ngrid): get data item from cell reference
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomiassaf committed Aug 19, 2019
1 parent a208636 commit cf5506b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
24 changes: 16 additions & 8 deletions libs/ngrid/src/lib/table/context/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,30 +351,38 @@ export class ContextApi<T = any> {
return this.rowContext(index);
}

getCell(cell: HTMLElement): PblNgridCellContext | undefined
getCell(cell: HTMLElement | GridDataPoint): PblNgridCellContext | undefined
/**
* Return the cell context for the cell at the point specified
* @param row
* @param col
*/
getCell(row: number, col: number): PblNgridCellContext | undefined;
getCell(rowOrCellElement: number | HTMLElement, col?: number): PblNgridCellContext | undefined {
getCell(rowOrCellElement: number | HTMLElement | GridDataPoint, col?: number): PblNgridCellContext | undefined {
if (typeof rowOrCellElement === 'number') {
const rowContext = this.rowContext(rowOrCellElement);
if (rowContext) {
return rowContext.cell(col);
}
} else {
const [ r, c ] = findCellRenderedIndex(rowOrCellElement);
const column = this.extApi.table.columnApi.findColumnAt(c);
const columnIndex = this.extApi.table.columnApi.indexOf(column);
const rowContext = this.rowContext(r);
if (rowContext) {
return rowContext.cell(columnIndex);
const ref = resolveCellReference(rowOrCellElement, this as any);
if (ref instanceof PblCellContext) {
return ref;
}
}
}

getDataItem(cell: CellReference): any {
const ref = resolveCellReference(cell, this as any);
if (ref instanceof PblCellContext) {
return ref.col.getValue(ref.rowContext.$implicit);
} else if (ref) {
const row = this.extApi.table.ds.source[ref[0].dataIndex];
const column = this.extApi.table.columnApi.findColumnAt(ref[1]);
return column.getValue(row);
}
}

createCellContext(renderRowIndex: number, column: PblColumn): PblCellContext<T> {
const rowContext = this.rowContext(renderRowIndex);
const colIndex = this.columnApi.indexOf(column);
Expand Down
3 changes: 2 additions & 1 deletion libs/ngrid/src/lib/table/context/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,13 @@ export interface PblNgridContextApi<T = any> {
*/
getRow(rowIndex: number | HTMLElement): PblNgridRowContext<T> | undefined;

getCell(cell: HTMLElement): PblNgridCellContext | undefined
getCell(cell: HTMLElement | GridDataPoint): PblNgridCellContext | undefined
/**
* Get the cell context in the specific row index and column index
* @param rowIndex The index position of the row.
* @param colIndex The index position of the column.
*/
getCell(rowIndex: number, colIndex: number): PblNgridCellContext<T> | undefined;

getDataItem(cell: CellReference): any;
}

0 comments on commit cf5506b

Please sign in to comment.