ng-repeat dynamic td including stripped rows/blank cells (td's) - widget

Pastupe
Mega Guru

Hello,

I need help on how to include stripped rows/cells if there are no data.

I created this exmaple widget and this is result

find_real_file.png

PS: in the data.table on server side I will be getting values empty in way there is no value at all, see here -->

["Name 1"] --> just one value

["Name 2","Hover 2"] --> 2 values

 

Server code:

(function() {



data.table = {"data":{

"columns":["Name","Hover"],
"cells":[

["Name 1"],["Name 2","Hover 2"],["Name 3", "Hover 3"]],

}}



})();

 

HTML:

 

<div class="table-responsive"><table class="table table-condensed table-striped">
<thead>
<tr>
<th ng-repeat="col in data.table.data.columns">{{ col }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="r in data.table.data.cells">
<td ng-repeat="cell in r">{{ cell }}</td>
</tr>

</tbody>
</table></div>

 

1 ACCEPTED SOLUTION

Jorn van Beek
Tera Guru

The issue is the cell is never created, therefore also not formatted. Best to solve this within the provided data. 

The way the data is provided raises a second issue. namely: If the arrays in the cells do not have the same number as the columns then you dont know what the missing column is.

For example:

You got 10 columns.

in your cells array you just have 8 values.

which 2 columns should remain empty? in your code this will always be column 9 and 10 which is most likely not correct.

to solve this a solution is to add an empty value to the first cells entry (and please call it rows, it is a bit confusing) like 

		"cells": [
			[
				"Name 1",
				""
			],
			[
				"Name 2",
				"Hover 2"
			],
			[
				"Name 3",
				"Hover 3"
			]
		]

 

View solution in original post

2 REPLIES 2

Jorn van Beek
Tera Guru

The issue is the cell is never created, therefore also not formatted. Best to solve this within the provided data. 

The way the data is provided raises a second issue. namely: If the arrays in the cells do not have the same number as the columns then you dont know what the missing column is.

For example:

You got 10 columns.

in your cells array you just have 8 values.

which 2 columns should remain empty? in your code this will always be column 9 and 10 which is most likely not correct.

to solve this a solution is to add an empty value to the first cells entry (and please call it rows, it is a bit confusing) like 

		"cells": [
			[
				"Name 1",
				""
			],
			[
				"Name 2",
				"Hover 2"
			],
			[
				"Name 3",
				"Hover 3"
			]
		]

 

Thansk for fast and correct answer.

This is now clear, thank you!

/Petr