Skip to content

Commit 7546a3b

Browse files
committed
Fix #522 - pfTableView: values added to wrong columns
1 parent 3b4df01 commit 7546a3b

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

src/table/tableview/examples/table-view-basic.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,24 +298,28 @@
298298
state: "New York"
299299
},
300300
{
301+
status: "ok",
301302
name: "Mike Bird",
302303
address: "50 Forth Street",
303304
city: "New York",
304305
state: "New York"
305306
},
306307
{
308+
status: "ok",
307309
name: "Cheryl Taylor",
308310
address: "2 Main Street",
309311
city: "New York",
310312
state: "New York"
311313
},
312314
{
315+
status: "ok",
313316
name: "Ren DiLorenzo",
314317
address: "10 Chase Lane",
315318
city: "Boston",
316319
state: "Massacusetts"
317320
},
318321
{
322+
status: "ok",
319323
name: "Kim Livingston",
320324
address: "5 Tree Hill Lane",
321325
city: "Boston",

src/table/tableview/table-view.component.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,6 @@ angular.module('patternfly.table').component('pfTableView', {
334334
}
335335
};
336336

337-
ctrl.isColItemFld = function (key) {
338-
var retVal = false;
339-
var tableCol = $filter('filter')(ctrl.columns, {itemField: key});
340-
341-
if (tableCol && tableCol.length === 1) {
342-
retVal = true;
343-
}
344-
345-
return retVal;
346-
};
347-
348337
ctrl.hasHTMLTemplate = function (key) {
349338
var htmlTemplate = this.getHTMLTemplate(key);
350339
return htmlTemplate.length > 0;

src/table/tableview/table-view.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<input type="checkbox" value="item.selected" ng-model="item.selected" ng-change="$ctrl.toggleOne(item)"/>
1818
</td>
1919

20-
<td ng-repeat="(key, value) in item" ng-if="$ctrl.isColItemFld(key)">
20+
<td ng-repeat="col in $ctrl.columns" ng-init="key = col.itemField; value = item[key]">
2121
<span ng-if="!$ctrl.hasHTMLTemplate(key)">{{value}}</span>
2222
<span ng-if="$ctrl.hasHTMLTemplate(key)" ng-include="$ctrl.getHTMLTemplate(key)"></span>
2323
</td>

test/table/tableview/table-view.spec.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ describe('Component: pfTableView', function () {
4040
];
4141

4242
$scope.items = [
43-
{uuid: '1', name: 'One', size: 291445030, capacity: 8200000000},
44-
{uuid: '2', name: 'Two', size: 1986231544, capacity: 8700000000},
45-
{uuid: '3', name: 'Three', size: 7864632, capacity: 7800000000},
46-
{uuid: '4', name: 'Four', size: 8162410, capacity: 3200000000},
47-
{uuid: '5', name: 'Five', size: 6781425410, capacity: 7600000000}
43+
{name: 'One', capacity: 8200000000, uuid: '1', size: 291445030},
44+
{name: 'Two', capacity: 8700000000, uuid: '2', size: 1986231544},
45+
{name: 'Three', capacity: 7800000000, uuid: '3', size: 7864632},
46+
{name: 'Four', capacity: 3200000000, uuid: '4', size: 8162410},
47+
{name: 'Five', capacity: 7600000000, uuid: '5', size: 6781425410}
4848
];
4949

5050
var htmlTmp = '<pf-table-view config="config" columns="columns" items="items"></pf-table-view>' +
@@ -78,6 +78,19 @@ describe('Component: pfTableView', function () {
7878
expect(rows.length).toBe($scope.items.length);
7979
});
8080

81+
it('should populate cells with correct data', function () {
82+
var i, j, item, selector, expectedValue;
83+
for (i = 0; i < $scope.items.length; i++) {
84+
item = $scope.items[i];
85+
for (j = 0; j < $scope.columns.length; j++) {
86+
selector = '.table > tbody > tr:eq(' + i + ') > td:eq(' + (j + 1) + ')';
87+
cellValue = element.find(selector).text().trim();
88+
expectedValue = item[$scope.columns[j].itemField].toString();
89+
expect(cellValue).toBe(expectedValue);
90+
}
91+
}
92+
});
93+
8194
it('should show checkboxes for row selection', function () {
8295
var headerCheckbox = element.find('.table > thead > tr > th > input[type="checkbox"]');
8396
var bodyCheckboxes = element.find('.table > tbody > tr > td > input[type="checkbox"]');

0 commit comments

Comments
 (0)