Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/models/gridOption.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface CustomDataView<T = any> {
getItem: (index: number) => T;
getItemMetadata(row: number, cell?: boolean | number): ItemMetadata | null;
getLength: () => number;
getCellValue?: (index: number, field: string) => T[keyof T];
}

export interface CssStyleHash {
Expand Down
25 changes: 24 additions & 1 deletion src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2738,7 +2738,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
rowInfo.startIndex = 0;
rowInfo.endIndex = rowInfo.rowCount - 1;
rowInfo.valueArr = null;
rowInfo.getRowVal = (j: number) => this.getDataItem(j)[columnDef.field as keyof TData];
rowInfo.getRowVal = (j: number) => this.getCellValue(j, columnDef.field as string);

const rowSelectionMode = (isInit ? autoSize.rowSelectionModeOnInit : undefined) || autoSize.rowSelectionMode;

Expand Down Expand Up @@ -3404,6 +3404,29 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}
}

/**
* Returns the value of a single field for a given row index.
*
* When the databinding source is a `CustomDataView` that implements the optional
* `getCellValue(index, field)` accessor, that method is used directly. This allows
* column-oriented (or otherwise non row-materializing) data sources to return a
* single cell value without first having to build a full row object via `getItem()`,
* which can be expensive when called repeatedly (e.g. during column content auto-sizing).
*
* Falls back to `getDataItem(i)[field]` for plain arrays or data sources that don't
* implement `getCellValue`.
*
* @param {Number} i Item row index.
* @param {String} field Column field name.
*/
getCellValue(i: number, field: string): TData[keyof TData] {
const customDataView = this.data as CustomDataView<TData>;
if (customDataView.getCellValue) {
return customDataView.getCellValue(i, field) as TData[keyof TData];
}
return this.getDataItem(i)[field as keyof TData];
}

/** Are we using a DataView? */
hasDataView() {
return !Array.isArray(this.data);
Expand Down
Loading