In a widget ng-repeat is adding 2 data rows per table row.

Janet Grace
Kilo Contributor

Hi.  I have run across an unusual issue where using ng-repeat to add data to table rows is resulting in 2 data rows in each table row.  FYI: the code is in a widget included in a portal page.  Please let me know if you have any ideas how this is happening and how to correct it. Thanks in advance!

Following is the HTML. Attached is a screen shot of the data and a screen shot of the results. 

<table ng-if="c.data.userHasSOCPermissions" class="table table-condensed table-runbook table-hover">
<thead>
<tr>
<th scope="col">Luna Account</th>
<th scope="col">Primary Contact</th>
<th scope="col">Primary Contact Email</th>
<th scope="col">Secondary Contact</th>
<th scope="col">Secondary Contact Email</th>
<th scope="col">Tertiary Contact</th>
<th scope="col">Tertiary Contact Email</th>
</tr>
</thead>
<tbody>
<tr class="app-row" ng-repeat="account in c.data.accounts">
<td scope="row">{{account.accountName}}</td>
<td scope="row">{{account.primaryOwnerName}}</td>
<td scope="row">{{account.primaryOwnerEmail}}</td>
<td scope="row">{{account.secondaryOwnerName}}</td>
<td scope="row">{{account.secondaryOwnerEmail}}</td>
<td scope="row">{{account.tertiaryOwnerName}}</td>
<td scope="row">{{account.tertiaryOwnerEmail}}</td>
</tr>
</tbody>
</table>

 

 

2 REPLIES 2

Rishabh Jha
Mega Guru

Hi @Janet Grace ,

 

It seems that your widget's server script is populating the data variable data.accounts twice. 

Since you haven't posted the widget's server and client script, but looking at the HTML template, since you're iterating over the data.accounts to show the rows, that's the culprit.

You can try logging the data.accounts variable on your server script by gs.info(JSON.stringify(data.accounts)) or console.log(JSON.stringify(data.accounts)), to see it on the browser's console, and see the data that it holds, and you'd probably see it has the duplicated rows.

Once you see that the data.accounts has duplicated rows, you'd need to clear the data.accounts variable at the top of your widget's server code by using : data.accounts = []; //assuming that it's an array of objects

This would ensure that data.accounts is empty when the server script executes at reload.

Also, check your widget's server and client scripts and verify that it's not populating the data.accounts variable at multiple places, that could be causing the duplicated rows.

 

Thanks & Regards,

Rishabh Jha

Aavenir (http://www.aavenir.com/)

Rishabh Jha
Mega Guru

Hi @Janet Grace ,

Hope you're doing well. Has this issue been resolved for you?

If my answer helped you in any way, please mark it as helpful/correct, so that other community members can refer to this as a resolved thread.

 

Thanks & Regards,

Rishabh Jha

Aavenir (https://www.aavenir.com/)