Skip to content

Commit 30b4827

Browse files
committed
Doco(gridOptions): fix #2578 change doco around options.data
1 parent 5140060 commit 30b4827

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/js/core/factories/GridOptions.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,37 @@ angular.module('ui.grid')
6969
* @name data
7070
* @propertyOf ui.grid.class:GridOptions
7171
* @description (mandatory) Array of data to be rendered into the grid, providing the data source or data binding for
72-
* the grid. The most common case is an array of objects, where each object has a number of attributes.
72+
* the grid.
73+
*
74+
* Most commonly the data is an array of objects, where each object has a number of attributes.
7375
* Each attribute automatically becomes a column in your grid. This array could, for example, be sourced from
74-
* an angularJS $resource query request. The array can also contain complex objects.
76+
* an angularJS $resource query request. The array can also contain complex objects, refer the binding tutorial
77+
* for examples of that.
78+
*
79+
* The most flexible usage is to set your data on $scope:
80+
*
81+
* `$scope.data = data;`
82+
*
83+
* And then direct the grid to resolve whatever is in $scope.data:
84+
*
85+
* `$scope.gridOptions.data = 'data';`
86+
*
87+
* This is the most flexible approach as it allows you to replace $scope.data whenever you feel like it without
88+
* getting pointer issues.
89+
*
90+
* Alternatively you can directly set the data array:
91+
*
92+
* `$scope.gridOptions.data = [ ];`
93+
* or
94+
*
95+
* `$http.get('/data/100.json')
96+
* .success(function(data) {
97+
* $scope.myData = data;
98+
* $scope.gridOptions.data = $scope.myData;
99+
* });`
100+
*
101+
* Where you do this, you need to take care in updating the data - you can't just update `$scope.myData` to some other
102+
* array, you need to update $scope.gridOptions.data to point to that new array as well.
75103
*
76104
*/
77105
baseOptions.data = baseOptions.data || [];

0 commit comments

Comments
 (0)