Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Commit 92b7a80

Browse files
authored
doc(datagrid): improve datagrid documentation (#66)
1 parent 111b5f2 commit 92b7a80

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

packages/oui-datagrid/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,99 @@ Clicked row action 1: <span ng-if="$ctrl.action1Row">{{$ctrl.action1Row.lastName
145145
</oui-datagrid>
146146
```
147147

148+
### Pagination
149+
150+
By default the page size is 25.
151+
152+
You can override this value by configuring it:
153+
154+
```javascript
155+
app.config(ouiDatagridConfigurationProvider => {
156+
ouiDatagridConfigurationProvider.setPageSize(10);
157+
});
158+
```
159+
160+
Or you can use the `page-size` property. It takes precedence over value configured by provider.
161+
162+
```html
163+
<oui-datagrid rows="$ctrl.data" page-size="10">
164+
<oui-column title="'firstName'" property="firstName"></oui-column>
165+
<oui-column title="$ctrl.lastNameText" property="lastName"></oui-column>
166+
</oui-datagrid>
167+
```
168+
169+
### Custom cell templates
170+
171+
```html
172+
<oui-datagrid rows="$ctrl.data">
173+
<oui-column title="'Name'">
174+
{{$row.firstName}} {{$row.lastName}}
175+
</oui-column>
176+
<oui-column property="email">
177+
<a href="mailto:{{$value}}">{{$value}}</a>
178+
</oui-column>
179+
<oui-column property="phone"></oui-column>
180+
<oui-column property="birth">
181+
{{$value | date:shortDate}}
182+
</oui-column>
183+
</oui-datagrid>
184+
```
185+
186+
### Remote data
187+
188+
```html
189+
<oui-datagrid rows-loader="$ctrl.loadData($config)">
190+
<oui-column property="firstName"></oui-column>
191+
<oui-column property="lastName"></oui-column>
192+
<oui-column property="email"></oui-column>
193+
<oui-column property="phone"></oui-column>
194+
<oui-column property="birth"></oui-column>
195+
</oui-datagrid>
196+
```
197+
198+
```javascript
199+
class YourController {
200+
loadData ({ offset, pageSize, sort }) {
201+
// Make what you want here
202+
return fetch("/path/to/you/api", {
203+
method: "POST",
204+
body: { offset, pageSize, sort }
205+
}).then(response => response.json());
206+
}
207+
}
208+
```
209+
210+
Your method must:
211+
212+
* return a promise or a compatible object
213+
* this promise must resolve a value of this shape:
214+
215+
```javascript
216+
{
217+
data: page, // your data (an array)
218+
meta: {
219+
totalCount // total number of items
220+
}
221+
}
222+
```
223+
224+
### Remote partial data
225+
226+
Sometimes you will have to get remote data, but you want to fill other cell from separate API calls or by calculating these new values.
227+
228+
You can use `row-loader`. It take the current row as argument and must return a promise that resolves to the transformed row.
229+
230+
```html
231+
<oui-datagrid rows-loader="$ctrl.loadPartialData($config)"
232+
row-loader="$ctrl.loadRow($row)">
233+
<oui-column property="firstName"></oui-column>
234+
<oui-column property="lastName"></oui-column>
235+
<oui-column property="email"></oui-column>
236+
<oui-column property="phone"></oui-column>
237+
<oui-column property="birth"></oui-column>
238+
</oui-datagrid>
239+
```
240+
148241
## API
149242

150243
### oui-datagrid

0 commit comments

Comments
 (0)