Using a custom template with a TableItem in Carbon Design (Angular) not yielding expected functionalityDynamic template URLs in Angular 2Angular HTTP GET with TypeScript error http.get(…).map is not a function in [null]Angular pass callback function to child component as @Input similar to AngularJS wayHow to declare a variable in a template in AngularAngular 2 template parse error Missing expected )What is let-* in Angular 2 templates?Angular with IBM carbon designUsing the environment variables in Angular 2 does not yield expected resultsSharing custom Angular formatting functions outside of template
Is there a tool to measure the "maturity" of a code in Git?
Is my sink P-trap too low?
Bit one of the Intel 8080's Flags register
What was the motivation for the invention of electric pianos?
Is the Dodge action perceptible to other characters?
What is the source of "You can achieve a lot with hate, but even more with love" (Shakespeare?)
How can I say "I want to" as a short response, omitting the main verb?
What is this gigantic dish at Ben Gurion airport?
International Orange?
How to control the output voltage of a solid state relay
Why don't airports use arresting gears to recover energy from landing passenger planes?
Why is this sentence grammatical?
Work done by spring force
If I want an interpretable model, are there methods other than Linear Regression?
Can I travel to European countries with the Irish passport and without destination Visa?
Asked to Not Use Transactions and to Use A Workaround to Simulate One
How to write characters doing illogical things in a believable way?
Masking out non-linear shapes on canvas
Impossible Scrabble Words
Why is belonging not transitive?
Would it be unbalanced to increase a druid's number of uses of Wild Shape based on level?
Seven Places at Once - Another Google Earth Challenge?
Block diagram vs flow chart?
How does a simple logistic regression model achieve a 92% classification accuracy on MNIST?
Using a custom template with a TableItem in Carbon Design (Angular) not yielding expected functionality
Dynamic template URLs in Angular 2Angular HTTP GET with TypeScript error http.get(…).map is not a function in [null]Angular pass callback function to child component as @Input similar to AngularJS wayHow to declare a variable in a template in AngularAngular 2 template parse error Missing expected )What is let-* in Angular 2 templates?Angular with IBM carbon designUsing the environment variables in Angular 2 does not yield expected resultsSharing custom Angular formatting functions outside of template
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
According to the IBM Carbon Design System docs, one can define an ng-template
and reference it using @ViewChild
and a protected
variable.
Then, when defining a new TableItem
, one should reference this variable and attach data associated with the template via the attribute let-data
, in summary:
import
TableItem,
TableHeaderItem
from 'carbon-components-angular';
/* ... */
export class HomeComponent implements OnInit {
@ViewChild('customItemTemplate')
protected customItemTemplate: TemplateRef<any>;
/* ... */
initialiseTable(records: any)
this.model = new TableModel();
this.model.header = [
new TableHeaderItem( data: 'Column name' ),
/* ... */
];
tableRow = [
new TableItem( data: name: 'Full details', link: '/record/' , template: this.customItemTemplate ),
/* ... */
];
this.model.data = [tableRow];
And in my component's HTML I have the following ng-template
:
<ng-template #customItemTemplate let-data="data">
<a [routerLink]="data.link">data.name</a>
</ng-template>
I've tried switching between different versions: 9.0.0 and 10.0.0.rc.0.
When I looked at the view, where the custom template ought to be, I see [object Object]
.
Can anyone help me fix this so that my template inserts properly and I can provide a link to another view?
Update: I have filed this as an issue on GitHub and had a really fast response. I was asked to offer a reduced demo which you can find via Codesandbox here. Related GitHub issue here
angular
add a comment
|
According to the IBM Carbon Design System docs, one can define an ng-template
and reference it using @ViewChild
and a protected
variable.
Then, when defining a new TableItem
, one should reference this variable and attach data associated with the template via the attribute let-data
, in summary:
import
TableItem,
TableHeaderItem
from 'carbon-components-angular';
/* ... */
export class HomeComponent implements OnInit {
@ViewChild('customItemTemplate')
protected customItemTemplate: TemplateRef<any>;
/* ... */
initialiseTable(records: any)
this.model = new TableModel();
this.model.header = [
new TableHeaderItem( data: 'Column name' ),
/* ... */
];
tableRow = [
new TableItem( data: name: 'Full details', link: '/record/' , template: this.customItemTemplate ),
/* ... */
];
this.model.data = [tableRow];
And in my component's HTML I have the following ng-template
:
<ng-template #customItemTemplate let-data="data">
<a [routerLink]="data.link">data.name</a>
</ng-template>
I've tried switching between different versions: 9.0.0 and 10.0.0.rc.0.
When I looked at the view, where the custom template ought to be, I see [object Object]
.
Can anyone help me fix this so that my template inserts properly and I can provide a link to another view?
Update: I have filed this as an issue on GitHub and had a really fast response. I was asked to offer a reduced demo which you can find via Codesandbox here. Related GitHub issue here
angular
add a comment
|
According to the IBM Carbon Design System docs, one can define an ng-template
and reference it using @ViewChild
and a protected
variable.
Then, when defining a new TableItem
, one should reference this variable and attach data associated with the template via the attribute let-data
, in summary:
import
TableItem,
TableHeaderItem
from 'carbon-components-angular';
/* ... */
export class HomeComponent implements OnInit {
@ViewChild('customItemTemplate')
protected customItemTemplate: TemplateRef<any>;
/* ... */
initialiseTable(records: any)
this.model = new TableModel();
this.model.header = [
new TableHeaderItem( data: 'Column name' ),
/* ... */
];
tableRow = [
new TableItem( data: name: 'Full details', link: '/record/' , template: this.customItemTemplate ),
/* ... */
];
this.model.data = [tableRow];
And in my component's HTML I have the following ng-template
:
<ng-template #customItemTemplate let-data="data">
<a [routerLink]="data.link">data.name</a>
</ng-template>
I've tried switching between different versions: 9.0.0 and 10.0.0.rc.0.
When I looked at the view, where the custom template ought to be, I see [object Object]
.
Can anyone help me fix this so that my template inserts properly and I can provide a link to another view?
Update: I have filed this as an issue on GitHub and had a really fast response. I was asked to offer a reduced demo which you can find via Codesandbox here. Related GitHub issue here
angular
According to the IBM Carbon Design System docs, one can define an ng-template
and reference it using @ViewChild
and a protected
variable.
Then, when defining a new TableItem
, one should reference this variable and attach data associated with the template via the attribute let-data
, in summary:
import
TableItem,
TableHeaderItem
from 'carbon-components-angular';
/* ... */
export class HomeComponent implements OnInit {
@ViewChild('customItemTemplate')
protected customItemTemplate: TemplateRef<any>;
/* ... */
initialiseTable(records: any)
this.model = new TableModel();
this.model.header = [
new TableHeaderItem( data: 'Column name' ),
/* ... */
];
tableRow = [
new TableItem( data: name: 'Full details', link: '/record/' , template: this.customItemTemplate ),
/* ... */
];
this.model.data = [tableRow];
And in my component's HTML I have the following ng-template
:
<ng-template #customItemTemplate let-data="data">
<a [routerLink]="data.link">data.name</a>
</ng-template>
I've tried switching between different versions: 9.0.0 and 10.0.0.rc.0.
When I looked at the view, where the custom template ought to be, I see [object Object]
.
Can anyone help me fix this so that my template inserts properly and I can provide a link to another view?
Update: I have filed this as an issue on GitHub and had a really fast response. I was asked to offer a reduced demo which you can find via Codesandbox here. Related GitHub issue here
angular
angular
edited Mar 28 at 19:04
OneLunch Man
2,1119 silver badges22 bronze badges
2,1119 silver badges22 bronze badges
asked Mar 28 at 12:14
gdgrgdgr
1,0242 gold badges10 silver badges29 bronze badges
1,0242 gold badges10 silver badges29 bronze badges
add a comment
|
add a comment
|
1 Answer
1
active
oldest
votes
I found the issue!
Believe it or not, it has to do with the code provided by IBM's documentation on Pagination.
The code in question which is causing issues by default with custom templates is this, used for the pagination functionality in the demo:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
let newData = [];
data.forEach(dataRow =>
let row = [];
dataRow.forEach(dataElement =>
row.push(new TableItem(
data: dataElement,
template: typeof dataElement === "string" ? undefined : this.paginationTableItemTemplate
// your template can handle all the data types so you don't have to conditionally set it
// you can also set different templates for different columns based on index
));
);
newData.push(row);
);
return newData;
For reference, here is the relevant documentation. If you scroll down to the header "Use pagination as table footer" you'll see the code I'm talking about :)
Solution
The function needs to check for the type coming through when prepareData
is called during pagination:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
const newData: Array<Array<TableItem>> = [];
data.forEach(dataRow =>
const row: Array<TableItem> = [];
dataRow.forEach(dataElement =>
let template;
if (dataElement.template)
template = dataElement.template;
else if (typeof dataElement === 'string')
template = undefined;
else
template = this.paginationTableItemTemplate;
row.push(
new TableItem(
data: dataElement.data,
template: template
)
);
);
newData.push(row);
);
return newData;
And now it works like a charm.
I have updated the team via GH and will see about a PR for the docs on this--it will not be uncommon that people copy the code and forget about it, like I did. It was only when I stripped back all functionality the custom templates started working, then I worked up from base principles.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397381%2fusing-a-custom-template-with-a-tableitem-in-carbon-design-angular-not-yielding%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I found the issue!
Believe it or not, it has to do with the code provided by IBM's documentation on Pagination.
The code in question which is causing issues by default with custom templates is this, used for the pagination functionality in the demo:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
let newData = [];
data.forEach(dataRow =>
let row = [];
dataRow.forEach(dataElement =>
row.push(new TableItem(
data: dataElement,
template: typeof dataElement === "string" ? undefined : this.paginationTableItemTemplate
// your template can handle all the data types so you don't have to conditionally set it
// you can also set different templates for different columns based on index
));
);
newData.push(row);
);
return newData;
For reference, here is the relevant documentation. If you scroll down to the header "Use pagination as table footer" you'll see the code I'm talking about :)
Solution
The function needs to check for the type coming through when prepareData
is called during pagination:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
const newData: Array<Array<TableItem>> = [];
data.forEach(dataRow =>
const row: Array<TableItem> = [];
dataRow.forEach(dataElement =>
let template;
if (dataElement.template)
template = dataElement.template;
else if (typeof dataElement === 'string')
template = undefined;
else
template = this.paginationTableItemTemplate;
row.push(
new TableItem(
data: dataElement.data,
template: template
)
);
);
newData.push(row);
);
return newData;
And now it works like a charm.
I have updated the team via GH and will see about a PR for the docs on this--it will not be uncommon that people copy the code and forget about it, like I did. It was only when I stripped back all functionality the custom templates started working, then I worked up from base principles.
add a comment
|
I found the issue!
Believe it or not, it has to do with the code provided by IBM's documentation on Pagination.
The code in question which is causing issues by default with custom templates is this, used for the pagination functionality in the demo:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
let newData = [];
data.forEach(dataRow =>
let row = [];
dataRow.forEach(dataElement =>
row.push(new TableItem(
data: dataElement,
template: typeof dataElement === "string" ? undefined : this.paginationTableItemTemplate
// your template can handle all the data types so you don't have to conditionally set it
// you can also set different templates for different columns based on index
));
);
newData.push(row);
);
return newData;
For reference, here is the relevant documentation. If you scroll down to the header "Use pagination as table footer" you'll see the code I'm talking about :)
Solution
The function needs to check for the type coming through when prepareData
is called during pagination:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
const newData: Array<Array<TableItem>> = [];
data.forEach(dataRow =>
const row: Array<TableItem> = [];
dataRow.forEach(dataElement =>
let template;
if (dataElement.template)
template = dataElement.template;
else if (typeof dataElement === 'string')
template = undefined;
else
template = this.paginationTableItemTemplate;
row.push(
new TableItem(
data: dataElement.data,
template: template
)
);
);
newData.push(row);
);
return newData;
And now it works like a charm.
I have updated the team via GH and will see about a PR for the docs on this--it will not be uncommon that people copy the code and forget about it, like I did. It was only when I stripped back all functionality the custom templates started working, then I worked up from base principles.
add a comment
|
I found the issue!
Believe it or not, it has to do with the code provided by IBM's documentation on Pagination.
The code in question which is causing issues by default with custom templates is this, used for the pagination functionality in the demo:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
let newData = [];
data.forEach(dataRow =>
let row = [];
dataRow.forEach(dataElement =>
row.push(new TableItem(
data: dataElement,
template: typeof dataElement === "string" ? undefined : this.paginationTableItemTemplate
// your template can handle all the data types so you don't have to conditionally set it
// you can also set different templates for different columns based on index
));
);
newData.push(row);
);
return newData;
For reference, here is the relevant documentation. If you scroll down to the header "Use pagination as table footer" you'll see the code I'm talking about :)
Solution
The function needs to check for the type coming through when prepareData
is called during pagination:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
const newData: Array<Array<TableItem>> = [];
data.forEach(dataRow =>
const row: Array<TableItem> = [];
dataRow.forEach(dataElement =>
let template;
if (dataElement.template)
template = dataElement.template;
else if (typeof dataElement === 'string')
template = undefined;
else
template = this.paginationTableItemTemplate;
row.push(
new TableItem(
data: dataElement.data,
template: template
)
);
);
newData.push(row);
);
return newData;
And now it works like a charm.
I have updated the team via GH and will see about a PR for the docs on this--it will not be uncommon that people copy the code and forget about it, like I did. It was only when I stripped back all functionality the custom templates started working, then I worked up from base principles.
I found the issue!
Believe it or not, it has to do with the code provided by IBM's documentation on Pagination.
The code in question which is causing issues by default with custom templates is this, used for the pagination functionality in the demo:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
let newData = [];
data.forEach(dataRow =>
let row = [];
dataRow.forEach(dataElement =>
row.push(new TableItem(
data: dataElement,
template: typeof dataElement === "string" ? undefined : this.paginationTableItemTemplate
// your template can handle all the data types so you don't have to conditionally set it
// you can also set different templates for different columns based on index
));
);
newData.push(row);
);
return newData;
For reference, here is the relevant documentation. If you scroll down to the header "Use pagination as table footer" you'll see the code I'm talking about :)
Solution
The function needs to check for the type coming through when prepareData
is called during pagination:
protected prepareData(data: Array<Array<any>>)
// create new data from the service data
const newData: Array<Array<TableItem>> = [];
data.forEach(dataRow =>
const row: Array<TableItem> = [];
dataRow.forEach(dataElement =>
let template;
if (dataElement.template)
template = dataElement.template;
else if (typeof dataElement === 'string')
template = undefined;
else
template = this.paginationTableItemTemplate;
row.push(
new TableItem(
data: dataElement.data,
template: template
)
);
);
newData.push(row);
);
return newData;
And now it works like a charm.
I have updated the team via GH and will see about a PR for the docs on this--it will not be uncommon that people copy the code and forget about it, like I did. It was only when I stripped back all functionality the custom templates started working, then I worked up from base principles.
answered Mar 29 at 8:38
gdgrgdgr
1,0242 gold badges10 silver badges29 bronze badges
1,0242 gold badges10 silver badges29 bronze badges
add a comment
|
add a comment
|
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55397381%2fusing-a-custom-template-with-a-tableitem-in-carbon-design-angular-not-yielding%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown