Skip to content

Commit 3ad45ad

Browse files
committed
Grid markup: Unit Price column and editors are now numeric; Master-Detail: restore original state on cancel/error
1 parent f643c79 commit 3ad45ad

File tree

8 files changed

+36
-20
lines changed

8 files changed

+36
-20
lines changed

samples/grid/master-detail/app/controllers/masterDetailController.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ app.controller('masterDetailController',
1010
$scope.message = '';
1111

1212
$scope.selectedHome = null;
13+
$scope.selectedHomeOriginal = null;
1314

1415
$scope.save = function(){
1516
dataService.save($scope.selectedHome).then(function(){
@@ -18,10 +19,12 @@ app.controller('masterDetailController',
1819
},
1920
function(error){
2021
$scope.error = error;
22+
angular.copy($scope.selectedHomeOriginal, $scope.selectedHome);
2123
});
2224
};
2325

2426
$scope.cancel = function(){
27+
angular.copy($scope.selectedHomeOriginal, $scope.selectedHome);
2528
$scope.selectedHome = null;
2629
};
2730

@@ -62,6 +65,8 @@ app.controller('masterDetailController',
6265
if($scope.homes[i].id === id){
6366
$scope.$apply(function () {
6467
debugger;
68+
$scope.selectedHomeOriginal = {};
69+
angular.copy($scope.homes[i], $scope.selectedHomeOriginal);
6570
$scope.selectedHome = $scope.homes[i];
6671
$scope.message = "'" + $scope.selectedHome.streetAddress + "' is selected";
6772
});

samples/grid/master-detail/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ <h1 class="push-down-md">igGrid Master/Detail</h1>
146146
</div>
147147
<div class="form-group">
148148
<div class="col-sm-offset-2 col-sm-10">
149-
<button class="btn btn-default btn-link" data-ng-click="cancel()">Cancel</button>
150149
<button class="btn btn-default btn-primary" data-ng-click="save()">Save</button>
150+
<button class="btn btn-default btn-link" data-ng-click="cancel()">Cancel</button>
151151
</div>
152152
</div>
153153
</form>
@@ -169,7 +169,6 @@ <h1 class="push-down-md">igGrid Master/Detail</h1>
169169
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
170170
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>
171171

172-
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>
173172
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular-resource.min.js"></script>
174173
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular-mocks.js"></script>
175174

samples/igGrid.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ <h1 class="push-down-md"><a href="http://igniteui.com/grid/overview" target="_bl
6969
<column key="ProductID" header-text="Product ID" width="50px" data-type="number"></column>
7070
<column key="ProductName" header-text="Name" width="250px" data-type="string"></column>
7171
<column key="QuantityPerUnit" header-text="Quantity per unit" width="200px" data-type="string"></column>
72-
<column key="UnitPrice" header-text="Unit Price" width="100px" data-type="string" template="{{getHtml('#colTmpl')}}"></column>
72+
<column key="UnitPrice" header-text="Unit Price" width="100px" data-type="number" template="{{getHtml('#colTmpl')}}"></column>
7373
</columns>
7474
<features>
7575
<feature name="Updating">
@@ -93,7 +93,7 @@ <h3>Add Product</h3>
9393
<div class="well well-sm">
9494
<input type="text" ng-model="newProduct.ProductName" class="form-control" placeholder="name">
9595
<input type="text" ng-model="newProduct.QuantityPerUnit" class="form-control" placeholder="quantity per unit">
96-
<input type="text" ng-model="newProduct.UnitPrice" class="form-control" placeholder="unit price">
96+
<input type="number" ng-model="newProduct.UnitPrice" class="form-control" placeholder="unit price">
9797
<input type="button" value="Add" ng-click="addProduct()" class="btn btn-default"/>
9898
</div>
9999

@@ -117,17 +117,18 @@ <h3>Add Product</h3>
117117
<td>{{product.ProductID}}</td>
118118
<td><input type="text" ng-model="product.ProductName" class="form-control" /></td>
119119
<td>{{product.QuantityPerUnit}}</td>
120-
<td> <input type="text" ng-model="product.UnitPrice" class="form-control" /> </td>
120+
<td> <input type="number" ng-model="product.UnitPrice" class="form-control" /> </td>
121121
<td><input type="button" value="Delete" ng-click="deleteProduct($index)" class="btn btn-default"/></td>
122122
</tr>
123123
</tbody>
124124
</table>
125125
<script id="colTmpl" type="text/template" ng-non-bindable>
126-
$ ${UnitPrice}
127-
{{if parseInt(${UnitPrice}) >= (Math.random()+0.5)*parseInt(${UnitPrice}) }}
128-
<img width='10' height='15' src= 'images/arrowUp.gif' />
126+
{{if ${UnitPrice} == null }}
127+
N/A
128+
{{elseif ${UnitPrice} >= (Math.random()+0.5)*${UnitPrice} }}
129+
$ ${UnitPrice} <img width='10' height='15' src= 'images/arrowUp.gif' />
129130
{{else}}
130-
<img width='10' height='15' src= 'images/arrowDown.gif' />
131+
$ ${UnitPrice} <img width='10' height='15' src= 'images/arrowDown.gif' />
131132
{{/if}}
132133
</script>
133134
</div>

samples/js/igniteui-sample.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ app.controller('gridController',
1717

1818
['$scope', 'northwind',
1919
function ($scope, northwind) {
20-
20+
// only needed until https://github.com/angular/angular.js/issues/6683 is resolved
21+
for (var i = 0; i < northwind.data.length; i++) {
22+
northwind.data[i].UnitPrice = parseFloat(northwind.data[i].UnitPrice);
23+
};
2124
$scope.northwind = northwind.data;
2225

2326
var createNewProduct = function () {

src-samples/src/grid/master-detail/app/controllers/masterDetailController.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ app.controller('masterDetailController',
1010
$scope.message = '';
1111

1212
$scope.selectedHome = null;
13+
$scope.selectedHomeOriginal = null;
1314

1415
$scope.save = function(){
1516
dataService.save($scope.selectedHome).then(function(){
@@ -18,10 +19,12 @@ app.controller('masterDetailController',
1819
},
1920
function(error){
2021
$scope.error = error;
22+
angular.copy($scope.selectedHomeOriginal, $scope.selectedHome);
2123
});
2224
};
2325

2426
$scope.cancel = function(){
27+
angular.copy($scope.selectedHomeOriginal, $scope.selectedHome);
2528
$scope.selectedHome = null;
2629
};
2730

@@ -62,6 +65,8 @@ app.controller('masterDetailController',
6265
if($scope.homes[i].id === id){
6366
$scope.$apply(function () {
6467
debugger;
68+
$scope.selectedHomeOriginal = {};
69+
angular.copy($scope.homes[i], $scope.selectedHomeOriginal);
6570
$scope.selectedHome = $scope.homes[i];
6671
$scope.message = "'" + $scope.selectedHome.streetAddress + "' is selected";
6772
});

src-samples/src/grid/master-detail/index.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ <h1 class="push-down-md">igGrid Master/Detail</h1>
116116
</div>
117117
<div class="form-group">
118118
<div class="col-sm-offset-2 col-sm-10">
119-
<button class="btn btn-default btn-link" data-ng-click="cancel()">Cancel</button>
120119
<button class="btn btn-default btn-primary" data-ng-click="save()">Save</button>
120+
<button class="btn btn-default btn-link" data-ng-click="cancel()">Cancel</button>
121121
</div>
122122
</div>
123123
</form>
@@ -128,7 +128,6 @@ <h1 class="push-down-md">igGrid Master/Detail</h1>
128128

129129

130130
|scripts|
131-
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular.min.js"></script>
132131
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular-resource.min.js"></script>
133132
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular-mocks.js"></script>
134133

src-samples/src/igGrid.html

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h1 class="push-down-md"><a href="http://igniteui.com/grid/overview" target="_bl
3939
<column key="ProductID" header-text="Product ID" width="50px" data-type="number"></column>
4040
<column key="ProductName" header-text="Name" width="250px" data-type="string"></column>
4141
<column key="QuantityPerUnit" header-text="Quantity per unit" width="200px" data-type="string"></column>
42-
<column key="UnitPrice" header-text="Unit Price" width="100px" data-type="string" template="{{getHtml('#colTmpl')}}"></column>
42+
<column key="UnitPrice" header-text="Unit Price" width="100px" data-type="number" template="{{getHtml('#colTmpl')}}"></column>
4343
</columns>
4444
<features>
4545
<feature name="Updating">
@@ -63,7 +63,7 @@ <h3>Add Product</h3>
6363
<div class="well well-sm">
6464
<input type="text" ng-model="newProduct.ProductName" class="form-control" placeholder="name">
6565
<input type="text" ng-model="newProduct.QuantityPerUnit" class="form-control" placeholder="quantity per unit">
66-
<input type="text" ng-model="newProduct.UnitPrice" class="form-control" placeholder="unit price">
66+
<input type="number" ng-model="newProduct.UnitPrice" class="form-control" placeholder="unit price">
6767
<input type="button" value="Add" ng-click="addProduct()" class="btn btn-default"/>
6868
</div>
6969

@@ -87,17 +87,18 @@ <h3>Add Product</h3>
8787
<td>{{product.ProductID}}</td>
8888
<td><input type="text" ng-model="product.ProductName" class="form-control" /></td>
8989
<td>{{product.QuantityPerUnit}}</td>
90-
<td> <input type="text" ng-model="product.UnitPrice" class="form-control" /> </td>
90+
<td> <input type="number" ng-model="product.UnitPrice" class="form-control" /> </td>
9191
<td><input type="button" value="Delete" ng-click="deleteProduct($index)" class="btn btn-default"/></td>
9292
</tr>
9393
</tbody>
9494
</table>
9595
<script id="colTmpl" type="text/template" ng-non-bindable>
96-
$ ${UnitPrice}
97-
{{if parseInt(${UnitPrice}) >= (Math.random()+0.5)*parseInt(${UnitPrice}) }}
98-
<img width='10' height='15' src= 'images/arrowUp.gif' />
96+
{{if ${UnitPrice} == null }}
97+
N/A
98+
{{elseif ${UnitPrice} >= (Math.random()+0.5)*${UnitPrice} }}
99+
$ ${UnitPrice} <img width='10' height='15' src= 'images/arrowUp.gif' />
99100
{{else}}
100-
<img width='10' height='15' src= 'images/arrowDown.gif' />
101+
$ ${UnitPrice} <img width='10' height='15' src= 'images/arrowDown.gif' />
101102
{{/if}}
102103
</script>
103104
</div>

src-samples/src/js/igniteui-sample.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ app.controller('gridController',
1717

1818
['$scope', 'northwind',
1919
function ($scope, northwind) {
20-
20+
// only needed until https://github.com/angular/angular.js/issues/6683 is resolved
21+
for (var i = 0; i < northwind.data.length; i++) {
22+
northwind.data[i].UnitPrice = parseFloat(northwind.data[i].UnitPrice);
23+
};
2124
$scope.northwind = northwind.data;
2225

2326
var createNewProduct = function () {

0 commit comments

Comments
 (0)