Bonjour,
j'ai créé un composant datagrid paginée et le clic sur le header fait un tri mais seulement sur la page affichée et non sur l'ensemble des données non paginées.
J'aimerais faire en sorte que le tri se fasse donc sur toutes mes données. Si quelqu'un à une idée.
(Le code est un peu long, désolé).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259 <?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" initialize="init()" xmlns:pagination="composant.pagination.*"> <mx:Script> <![CDATA[ import mx.containers.Box; import mx.containers.ViewStack; import mx.events.ItemClickEvent; import mx.collections.ArrayCollection; import mx.controls.DataGrid; [Bindable] private var __listePages:ViewStack = new ViewStack(); private var __nbPagesVisibles:int = 10; private var __pageCourante:int; /** * data provider pour la pagination * this code assumes you use an arrayCollection as a data provider */ private var __collectionComplete:ArrayCollection = new ArrayCollection(); private var __nbEnregistrements:int; private var __nbPages:int; private var start:int; [Bindable] public var __maListePaginee:ArrayCollection = new ArrayCollection(); private var __nbLignesAAfficher:int; private var __numeroPage:int; public function get collectionComplete():ArrayCollection{ return __collectionComplete; } public function set collectionComplete(pCollectionComplete:ArrayCollection):void{ __collectionComplete = pCollectionComplete; } public function get nbLignes():int{ return __nbLignesAAfficher; } public function set nbLignes(pNbLignes:int):void{ __nbLignesAAfficher = pNbLignes; } public function init():void { for (var i:int = 0; i < 50; i++) { __collectionComplete.addItem(i+1); } start = 0; linkBar.addEventListener(ItemClickEvent.ITEM_CLICK, changerPage); linkPremiere.addEventListener(MouseEvent.CLICK, changerPagePremiere); linkPrecedente.addEventListener(MouseEvent.CLICK, changerPagePrecedente); linkSuivante.addEventListener(MouseEvent.CLICK, changerPageSuivante); linkDerniere.addEventListener(MouseEvent.CLICK, changerPageDerniere); paginer(); } private function paginer():void { __nbEnregistrements = __collectionComplete.length; __nbPages = Math.ceil(__nbEnregistrements/ __nbLignesAAfficher); dp.rowCount = __nbLignesAAfficher; __pageCourante = 1; afficherNbPages(__pageCourante); afficheDataProvider(start); } /** * Fonction pour l'affichage d'une page dans le data grid */ private function afficheDataProvider(pStart:int):void{ __numeroPage = pStart+1; __maListePaginee = new ArrayCollection(__collectionComplete.toArray().slice((pStart * __nbLignesAAfficher),(pStart * __nbLignesAAfficher) + __nbLignesAAfficher)); } /********************************************** * Barre de navigation *********************************************/ /** * Récupération de la liste de pages */ public function afficherNbPages(pPageCourante:int):void { linkPremiere.visible = false; linkPrecedente.visible = false; linkSuivante.visible = false; linkDerniere.visible = false; if (pPageCourante == 0 || __nbPages <= 1) { __listePages.removeAllChildren(); if(__nbPages <= 1){ marquePage.includeInLayout = false; __nbPages = 1; } else { linkSuivante.label = ">"; linkDerniere.label = ">>"; for (var i:int = 1; i <= __nbPages && i <= __nbPagesVisibles; i++){ var box:Box = new Box(); box.label = i.toString(); __listePages.addChild(box); } __pageCourante = 1; marquePage.includeInLayout = true; linkBar.selectedIndex = 0; } } else { if (__pageCourante > 1) { linkPremiere.visible = true; linkPrecedente.visible = true; } if (__pageCourante < __nbPages) { linkDerniere.visible = true; linkSuivante.visible = true; } var unNombrePageFixeMin:int = __nbPagesVisibles/2 ; var unNombrePageFixeMax:int = __nbPages - unNombrePageFixeMin ; if (unNombrePageFixeMax < unNombrePageFixeMin ) { unNombrePageFixeMax = unNombrePageFixeMin; } if (pPageCourante <= unNombrePageFixeMin || __nbPages <= __nbPagesVisibles) { __listePages.removeAllChildren(); for (i = 1; i <= __nbPages && i <= __nbPagesVisibles; i++){ box = new Box(); box.label = i.toString(); __listePages.addChild(box); } marquePage.includeInLayout = true; linkBar.selectedIndex = pPageCourante-1; } else if ( pPageCourante >= unNombrePageFixeMax) { __listePages.removeAllChildren(); for (i = __nbPages - __nbPagesVisibles +1 ; i <= __nbPages; i++){ box = new Box(); box.label = i.toString(); __listePages.addChild(box); } marquePage.includeInLayout = true; linkBar.selectedIndex = __nbPagesVisibles - (__nbPages- __pageCourante) -1; } else if (pPageCourante > unNombrePageFixeMin && pPageCourante < unNombrePageFixeMax){ __listePages.removeAllChildren(); for (i = pPageCourante- unNombrePageFixeMin + 1; i <= __nbPages && i <= pPageCourante- unNombrePageFixeMin + __nbPagesVisibles; i++){ box = new Box(); box.label = i.toString(); __listePages.addChild(box); } marquePage.includeInLayout = true; linkBar.selectedIndex = unNombrePageFixeMin -1; } } linkPremiere.tabEnabled= linkPremiere.visible ; linkPrecedente.tabEnabled= linkPrecedente.visible ; linkSuivante.tabEnabled = linkSuivante.visible ; linkDerniere.tabEnabled= linkDerniere.visible ; } /****************************************************** * Gestion de la navigation entre les pages * *******************************/ /** * Affiche la page demandée */ private function changerPage(pEvent:ItemClickEvent):void { __pageCourante = int(pEvent.label); afficherNbPages(__pageCourante); afficheDataProvider(__pageCourante-1); } /** * Affiche la première page */ private function changerPagePremiere(pEvent:MouseEvent):void { __pageCourante = 1; __listePages.removeAllChildren(); afficherNbPages(__pageCourante); afficheDataProvider(__pageCourante-1); } /** * Affiche la page précédent la page actuelle */ private function changerPagePrecedente(pEvent:MouseEvent):void { if (__pageCourante > 1) { __pageCourante--; afficherNbPages(__pageCourante); afficheDataProvider(__pageCourante-1); } } /** * Affiche la page suivant la page courante */ private function changerPageSuivante(pEvent:MouseEvent):void { // Problème d'initialisation if (__pageCourante == 0) { __pageCourante = 1; } if (__pageCourante < __nbPages){ __pageCourante++; afficherNbPages(__pageCourante); afficheDataProvider(__pageCourante-1); } } /** * Affiche la dernière page */ private function changerPageDerniere(pEvent:MouseEvent):void { __pageCourante = __nbPages; afficherNbPages(__pageCourante); afficheDataProvider(__pageCourante-1); } ]]> </mx:Script> <mx:VBox > <mx:DataGrid id="dp" dataProvider="{__maListePaginee}"> <mx:columns> <mx:DataGridColumn headerText="plop"/> </mx:columns> </mx:DataGrid> <mx:HBox id="marquePage" width="100%" height="25" horizontalGap="0" verticalAlign="middle"> <mx:Spacer width="1"/> <mx:LinkButton id="linkPremiere" width="37" tabEnabled="true" label="<<" /> <mx:LinkButton id="linkPrecedente" width="26" tabEnabled="true" label="<" /> <mx:LinkBar id="linkBar" verticalAlign="middle" textDecoration="underline" disabledColor="#bbbbbb" dataProvider="{__listePages}" /> <mx:LinkButton id="linkSuivante" width="26" tabEnabled="true" label=">"/> <mx:LinkButton id="linkDerniere" width="37" tabEnabled="true" label=">>"/> </mx:HBox> </mx:VBox> </mx:Canvas>
Merci pour votre aide
Partager