(), {
- content: '',
- items: () => [],
verticalHeader: true,
caption: undefined,
- offset: 1,
extraContent: null
})
@@ -90,13 +90,14 @@ const handleClick = () => {
const hasComponent = (column: any) =>
typeof column === 'object' && column.hasOwnProperty('component')
-const getCellText = (colIndex: number) => {
- const column = props.columns[colIndex]
- const objectKey = column.objectKey
+const getCellText = (col?: number | string, value = '') => {
+ if (typeof col === 'undefined') return value
+
+ const objectKey = typeof col === 'string' ? col : props.columns[col].objectKey
return typeof props.row === 'object' && props.row.hasOwnProperty(objectKey)
? props.row[objectKey]
- : ''
+ : value
}
@@ -123,7 +124,6 @@ const getCellText = (colIndex: number) => {
-
{
|
+
+
+
{
{{ item.heading }}
- {{ item.content }}
+
+
+
+ {{ getCellText(item?.objectKey, item.content) }}
-
+ />
|
diff --git a/packages/ripple-ui-core/src/components/data-table/fixtures/sample.ts b/packages/ripple-ui-core/src/components/data-table/fixtures/sample.ts
index 359236c44b..dcb6978b1a 100644
--- a/packages/ripple-ui-core/src/components/data-table/fixtures/sample.ts
+++ b/packages/ripple-ui-core/src/components/data-table/fixtures/sample.ts
@@ -21,7 +21,7 @@ export const RplDataTableItems = [
col3: 'R2 - C3',
col4: 'R2 - C4',
__extraContent: {
- html: 'R2 test heading R2 test content '
+ html: 'R2 test heading R2 test content '
}
},
{
@@ -88,11 +88,12 @@ export const RplDataTableStructuredItems = [
col2: 'R3 - C2',
col3: 'R3 - C3',
col4: 'R3 - C4',
+ col5: 'R3 - Extra content cell',
__extraContent: {
items: [
{
- heading: 'R3 test heading',
- content: 'R3 test content'
+ heading: 'R3 with object key',
+ objectKey: 'col5'
}
]
}
@@ -102,25 +103,25 @@ export const RplDataTableStructuredItems = [
export const RplDataTableComplexItems = [
{
title: 'Turtle',
- url: 'www.google.com',
+ url: 'https://www.google.com',
speed: 'Slow',
type: 'Reptile'
},
{
title: 'Dog',
- url: 'www.google.com',
+ url: 'https://duckduckgo.com',
speed: 'Medium',
type: 'Mammal'
},
{
title: 'Horse',
- url: 'www.google.com',
+ url: 'https://www.vic.gov.au',
speed: 'Fast',
type: 'Mammal'
},
{
title: 'Cheetah',
- url: 'www.google.com',
+ url: 'https://www.ripple.sdp.vic.gov.au',
speed: 'Fastest',
type: 'Mammal'
}
@@ -186,3 +187,50 @@ export const RplDataTableObjects = [
type: 'Bird'
}
]
+
+export const RplDataTableExtraComponents = [
+ {
+ name: 'George',
+ age: 20,
+ type: 'Lizard',
+ image: '/img/image-landscape-s.jpg',
+ __extraContent: {
+ component: {
+ props: {
+ item: Object
+ },
+ template: ``
+ }
+ }
+ },
+ {
+ name: 'Fred',
+ age: 50,
+ type: 'Cat',
+ __extraContent: {
+ component: {
+ props: {
+ item: Object
+ },
+ template: `
+ {{ item.name }} the {{ item.age }} year old {{ item.type }} was an inspiration to us all.`
+ }
+ }
+ },
+ {
+ name: 'Sue',
+ age: 20,
+ type: 'Dog',
+ __extraContent: {
+ component: {
+ props: {
+ item: Object
+ },
+ template: `
+
+ Find out more about {{ item.name }} the {{ item.age }} year old {{ item.type }}
+ `
+ }
+ }
+ }
+]
|