forked from agiliq/django-datagrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.txt
45 lines (27 loc) · 1.01 KB
/
examples.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Examples
-------------------
1. Simplest
1.1 Create a Grid:
class SimpleGrid(DataGrid):
name = NonDatabaseColumn("Hello")
1.2 In the views
def simple(request):
books = Book.objects.all()
return SimpleGrid(request, books).render_to_response("mylibrary/simple.html")
This creates a view with as many rows as the elemns in `books` queryset.
2. A little better.
OK that grid is useless, lets createa one with real data.
class RealGrid(DataGrid):
name = Column()
publisher = Column()
recommended_by = Column()
This will show the attributes named `name`, `publisher` and `recommended_by`.
view remains about same.
def real(request):
books = Book.objects.all()
return RealGrid(request, books).render_to_response("mylibrary/real.html")
3. Cool lets add sorting.
class RealGrid(DataGrid):
name = Column(sortable = True)
publisher = Column(sortable = True)
recommended_by = Column(sortable = True)