Skip to content

Commit 685c9d2

Browse files
Zhuk, AlexanderZhuk, Alexander
authored andcommitted
API description update
1 parent 3eabc58 commit 685c9d2

File tree

1 file changed

+50
-25
lines changed

1 file changed

+50
-25
lines changed

README.md

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
##Angular Data Grid
2-
32
Light and flexible Data Grid for AngularJS apps, with built-in sorting, pagination and filtering options, unified API for client-side and server-side data fetching,
4-
seamless synchronization with browser address bar and total freedom in choosing mark-up and styling suitable for your application.
3+
seamless synchronization with browser address bar and total freedom in mark-up and styling suitable for your application.
54

6-
Demo Material Design: http://angular-data-grid.github.io/demo/
5+
Demo Material Design: http://angular-data-grid.github.io/demo/material.html
76
Demo Bootstrap: http://angular-data-grid.github.io/
87

98
### Features
10-
119
- Does not have any hard-coded template so you can choose any mark-up you need, from basic ```<table>``` layout to any ```<div>``` structure.
1210
- Easily switch between the most popular Bootstrap and Google Material theming, or apply your own CSS theme just by changing several CSS classes.
1311
- Built-in sync with browser address bar (URL), so you can copy-n-paste sorting/filtering/pagination results URL and open it in other browser / send to anyone - even if pagination / filtering are done on a client-side.
1412
- Unlike most part of other Angular DataGrids, we intentionally use non-isolated scope of the directive to maximize flexibility, so it can be easily synchronized with any data changes inside your controller. !With great power comes great responsibility, so be careful to use non-isolated API correctly.
1513

1614
### Installation
17-
1815
- Using Bower
1916

2017
```
@@ -23,11 +20,10 @@ bower install angular-data-grid
2320

2421
- Download ZIP archive [from here](https://github.com/angular-data-grid/angular-data-grid.github.io/archive/master.zip)
2522

26-
Then use files from ```dist``` folder.
23+
> Then use files from ```dist``` folder (see below).
2724
2825
### Setup
29-
30-
1. Include scripts in you application: dataGrid.min.js and pagination.min.js (include the second one only if you need pagination), like:
26+
1. Include scripts in you application: ```dataGrid.min.js``` and ```pagination.min.js``` (include the second one only if you need pagination), like:
3127

3228
```javascript
3329
<script src="components/angular-data-grid/pagination.min.js"></script>
@@ -40,9 +36,15 @@ bower install angular-data-grid
4036
angular.module('myApp', ['dataGrid', 'pagination'])
4137
```
4238

43-
3. Initialize grid with additional options in your controller
39+
3. Initialize grid with additional options in your controller. To do that, add ```grid-data``` directive to element and pass 2 required parameters ```grid-options``` and ```grid-actions```:
40+
41+
```HTML
4442

45-
JS:
43+
<div grid-data id='test' grid-options="gridOptions" grid-actions="gridActions">
44+
/// grid mark-up goes here
45+
</div>
46+
47+
```
4648

4749
```javascript
4850
$scope.gridOptions = {
@@ -64,19 +66,8 @@ JS:
6466
urlSync: true
6567
};
6668
```
67-
68-
And HTML:
69-
70-
```HTML
71-
72-
<div grid-data id='test' grid-options="gridOptions" grid-actions="gridActions">
73-
/// grid mark-up goes here
74-
</div>
75-
76-
```
7769

7870
### Fetch Data
79-
8071
- For client-side pagination/filtering to fetch all data at once: just assign ```gridOptions.data``` to any JSON array object.
8172

8273
- For server side pagination/filtering to fetch data by page: assign ```getData``` method to some function with URL params as 1st parameter and data itself as 2d parameter:
@@ -94,21 +85,55 @@ And HTML:
9485
```
9586
9687
### Sorting
97-
You can use the sortable directive to have a built in sort feature. You add the attribute sortable to your table headers. This will specify the property name you want to sort by. Also if you add class sortable to your element, sort arrows will be displayed for acs/decs sort directions.
88+
To enable sorting, just add attribute ```sortable``` to your table headers. This will specify the property name you want to sort by. Also you can add class ```sortable``` to display acs/decs arrows.
9889
99-
You can use Data Grid module to easily display data in grids with built-in sorting, outer filters and url-synchronization. To use it, you must add grid-data directive to element and pass 2 required parameters ```grid-options``` and ```grid-actions```.
90+
```HTML
91+
<th sortable="code" class="sortable">
92+
Order #
93+
</th>
94+
<th sortable="placed" class="sortable">
95+
Date Placed
96+
</th>
97+
```
10098
99+
### Basic API
101100
```grid-options``` : Name of object in your controller with start options for grid. You must create this object with at least 1 required parameter - data.
102101
103102
```grid-actions```: Name of object in your controller with functions for updating grid. You can can just pass string or create empty object in controller. Use this object for calling methods of directive: sort, filter, refresh.
104103
105-
Inside the ```grid-data``` directive you can use grid-pagination directive. It's just wrapper of angular-ui pagination directive. You can pass any parameters from pagination directive. Also you can use grid-item-per-page directive and pass into it array of value (f.e. "10, 25, 50"). If you need get size of current displayed items you can use filtered variable.
104+
Inside the ```grid-data``` directive you can use grid-pagination directive. You can pass any parameters from pagination directive. Also you can use grid-item-per-page directive and pass into it array of value (e.g. "10, 25, 50"). If you need get size of current displayed items you can use filtered variable.
106105
107106
### Filters
108-
Data Grid module has 4 types built in filters. To use it, you must add attribute filter-by to any element and pass property name, which you want filtering. Also you need add attribute filter-type with type of filter (text, select, dateFrom, dateTo). After that you need call filter() method in ng-change for text or select inputs and in ng-blur/ng-focus for datepickers. Filters synchronize with URL by ng-model value.
107+
Data Grid supports 4 built-in types of filters: ```text```, ```select```, ```dateFrom``` and ```dateTo```. To use it, add attribute ```filter-by``` to any element and pass property name, which you want filtering. Also you need add attribute ```filter-type``` with type of filter. After that you need call ```filter()``` method in ```ng-change``` for text or select inputs and in ```ng-blur/ng-focus``` for datepickers. Filters synchronize with URL by ```ng-model``` value.
108+
109+
```HTML
110+
111+
<input type="text" class="form-control order-search-box"
112+
placeholder="Search By Order #"
113+
ng-change="gridActions.filter()"
114+
ng-model="code"
115+
filter-by="code"
116+
filter-type="text">
117+
118+
```
109119
110120
### Custom Filters
111121
If you need use some custom filters (f.e. filter by first letter), you must add filter-by to specify property name, which you want filtering and add ng-model property. Then create in gridOptions.customFilters variable named as it ng-model value and contain filtering function. Filtering function accept items, value, predicate arguments and must return filtered array.
112122
123+
```javascript
124+
125+
$scope.gridOptions = {
126+
data: [],
127+
customFilters: {
128+
startFrom: function (items, value, predicate) {
129+
return items.filter(function (item) {
130+
return value && item[predicate] ? !item[predicate].toLowerCase().indexOf(value.toLowerCase()) : true;
131+
});
132+
}
133+
}
134+
};
135+
136+
```
137+
113138
### Others
114139
All filters has parameter disable-url. If you set it as true value - URL-synchronization for this filter will be disabled. If you need use 2 or more grids on page, you must add id to grids, and use grid-id attribute on filters to specify their grid.

0 commit comments

Comments
 (0)