-
Notifications
You must be signed in to change notification settings - Fork 12
Customize cell content, fixes #12 #37
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ import * as tableCss from './styles/shared/table.m.css'; | |
export const RowBase = ThemeableMixin(RegistryMixin(WidgetBase)); | ||
|
||
export interface RowProperties extends WidgetProperties, HasColumns, RegistryMixinProperties, ThemeableProperties { | ||
item: ItemProperties<any>; | ||
item: ItemProperties; | ||
key: string; | ||
} | ||
|
||
|
@@ -37,15 +37,40 @@ class Row extends RowBase<RowProperties> { | |
classes: this.classes(tableCss.table, css.rowTable) | ||
}, [ | ||
v('tr', columns.map((column) => { | ||
const { id, field } = column; | ||
const { field, id } = column; | ||
|
||
let value: any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps would be nicer it could be simplified a bit (does assume consolidating the two render functions): let value = item.data[ field || id] ? String(item.data[ field || id ]) : '';
if (column.get) {
value = column.get(item, column);
}
let content: DNode = value;
if (column.render) {
content = column.render(item, column, value);
} |
||
if (typeof column.get === 'function') { | ||
// Get the value from the column callback | ||
value = column.get(item, column); | ||
} | ||
else if (typeof column.get !== 'undefined') { | ||
// Get the value from the column property | ||
value = column.get; | ||
} | ||
else { | ||
// Get the value using a property lookup on the item data | ||
value = item.data[ field || id ]; | ||
} | ||
|
||
let content: DNode; | ||
if (column.render) { | ||
// The column callback calculates its own value and DNode/string | ||
content = column.render({ value, item, column }); | ||
} | ||
else { | ||
// The value from get/item data is cast to a string | ||
content = String(value); | ||
} | ||
|
||
return w<Cell>('cell', { | ||
content, | ||
column, | ||
item, | ||
key: id, | ||
registry, | ||
theme, | ||
value: item.data[ field || id ] | ||
value | ||
}); | ||
})) | ||
]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,50 @@ | ||
export interface Column<T> { | ||
import { DNode } from '@dojo/widget-core/interfaces'; | ||
|
||
/** | ||
* @type Column | ||
* | ||
* Adds information about a column that will be used by the | ||
* grid when retrieving and displaying data. | ||
* | ||
* @typeparam T Used by field property and cell customization functions to enforce type safety | ||
* @typeparam V Used by cell customization to ensure the same type is used by get and render | ||
* @property field Property on the row's data item to use to look up the column's value | ||
* @property get Manually return the value or content to use for this column | ||
* @property id A unique identifier for this column | ||
* @property label The label to use in the column's header | ||
* @property sortable Set to false to indicate the column is not sortable | ||
* @property render Use this column's value to provide content for this column | ||
*/ | ||
export interface Column<T = any, V = string> { | ||
field?: keyof T; | ||
get?: V | ((item: ItemProperties<T>, column: Column<T>) => V); | ||
id: string; | ||
label?: string; | ||
sortable?: boolean; // default true | ||
render?(options: ColumnRenderOptions<T, V>): DNode; | ||
} | ||
|
||
export interface ColumnRenderOptions<T = any, V = string> { | ||
column: Column<T>; | ||
item: ItemProperties<T>; | ||
value: V; | ||
} | ||
|
||
export interface DataProperties<T> { | ||
items: ItemProperties<T>[]; | ||
sort?: SortDetails[]; | ||
} | ||
|
||
export interface HasContent { | ||
content: DNode; | ||
} | ||
|
||
export interface HasColumn { | ||
column: Column<any>; | ||
column: Column<any, any>; | ||
} | ||
|
||
export interface HasColumns { | ||
columns: Column<any>[]; | ||
columns: Column<any, any>[]; | ||
} | ||
|
||
export interface HasSortDetail { | ||
|
@@ -35,18 +64,18 @@ export interface HasSortEvent { | |
} | ||
|
||
export interface HasItem { | ||
item: ItemProperties<any>; | ||
item: ItemProperties; | ||
} | ||
|
||
export interface HasItems { | ||
items: ItemProperties<any>[]; | ||
items: ItemProperties[]; | ||
} | ||
|
||
export interface HasValue { | ||
value: string; | ||
} | ||
|
||
export interface ItemProperties<T> { | ||
export interface ItemProperties<T = any> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I understanding correctly that dgrid requires data objects to look like this: {
id: <idValue>,
data: {
<... data properties>
}
} Are we not able to continue dgrid 1's design of accepting flatter objects (with support for {
id: <idValue>,
<... data properties>
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, the object structure is simple, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be very good if dgrid 2 is able to continue supporting data in the same format as dgrid 1 unless there's a compelling reason not to - is there? While Dojo's data solutions have evolved over the years, the basic format of a data object has been consistent for years. What is the compelling need to change it? Also - considering dgrid 2 requires a data provider, are my concerns relevant? Can one store be used for consumers that like the old data format, and also for dgrid, with the differences implemented in the data provider? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't really have anything to do with the data - it's what the data provider gives to the grid. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok great! |
||
id: string; | ||
data: T; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of
HasValue
forCell
? It's not used in the rendering... is it envisioned that one might want to read the value ofvalue
from aCell
instance?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my thought, yes.