/
ViewSettingsDialog.html
1553 lines (1447 loc) · 47.6 KB
/
ViewSettingsDialog.html
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html>
<head>
<title>ViewSettingsDialog - sap.m</title>
<script src="shared-config.js"></script>
<script src="../../../resources/sap-ui-core.js"
id="sap-ui-bootstrap" data-sap-ui-libs="sap.m"
data-sap-ui-xx-bindingSyntax="complex">
</script>
<style>
.debugPanel { margin-top: 2rem; }
.customPriceFilter { margin: 1rem; }
</style>
<script>
jQuery.sap.require("sap.m.MessageBox");
jQuery.sap.require("sap.m.MessageToast");
// initialize application first
var app = new sap.m.App();
var debug = new sap.m.TextArea({
editable : true,
width : "100%",
rows : 10
});
var debugSelectedFilterItems = function (aItems) {
var sFilterString = "",
i = 0;
if (!aItems) {
return;
}
for (; i < aItems.length; i++) {
sFilterString += aItems[i].getText() + ", ";
}
return sFilterString.substring(0, sFilterString.length - 2);
};
/******************************
* Table setup and formatting *
******************************/
/* custom formatters (taken from cart app to test custom formatters) */
jQuery.sap.declare("util.Formatter");
util.Formatter = {
price: function (value) {
jQuery.sap.require("sap.ui.core.format.NumberFormat");
var numberFormat = sap.ui.core.format.NumberFormat.getFloatInstance({
maxFractionDigits: 2,
groupingEnabled: true,
groupingSeparator: ".",
decimalSeparator: ","
});
return numberFormat.format(value);
},
_statusTextMap: {
"A": "Approved",
"O": "Open",
"D": "Denied"
},
statusText: function (status) {
return (util.Formatter._statusTextMap[status]) ? util.Formatter._statusTextMap[status]: status;
},
_statusStateMap: {
"A": "Success",
"O": "Warning",
"D": "Error"
},
statusState: function (status) {
return (util.Formatter._statusStateMap[status]) ? util.Formatter._statusStateMap[status]: "None";
}
};
/* column data and model */
var model = new sap.ui.model.json.JSONModel();
model.setData({
Name: "Name",
Status: "Status",
Value: "Value",
Price: "Price"
});
sap.ui.getCore().setModel(model, "i18n");
/* table definition */
var table = new sap.m.Table("items", {
threshold: 2,
inset: false,
mode: "MultiSelect",
showUnread: true,
scrollToLoad: true,
infoToolbar:
new sap.m.Toolbar({
visible: false,
active: true,
press: function (evt) {
sap.m.MessageToast.show("InfoBar Pressed!");
},
content: [
new sap.m.Label({
text: "Filter text goes here"
}),
new sap.m.ToolbarSpacer(),
new sap.ui.core.Icon({
src : "sap-icon://add-filter"
})
]
}),
columns: [new sap.m.Column({
styleClass: "name",
hAlign: "Left",
header: new sap.m.Label({
text: "{i18n>/Name}"
})
}), new sap.m.Column({
hAlign: "Center",
styleClass: "qty",
width: "20%",
popinDisplay: "Inline",
header: new sap.m.Label({
text: "{i18n>/Status}"
}),
minScreenWidth: "Tablet",
demandPopin: true
}), new sap.m.Column({
hAlign: "Right",
styleClass: "limit",
width: "20%",
header: new sap.m.Label({
text: "{i18n>/Value}"
}),
minScreenWidth: "XXSmall",
demandPopin: true
}), new sap.m.Column({
hAlign: "Right",
styleClass: "price",
width: "20%",
popinDisplay: "Inline",
header: new sap.m.Label({
text: "{i18n>/Price}"
}),
footer: new sap.m.Label({
text: "130.00 EUR"
}),
minScreenWidth: "400px",
demandPopin: true
})]
});
var template = new sap.m.ColumnListItem({
type: "Navigation",
unread: false,
cells: [
new sap.m.Label({
text: "{name}"
}),
new sap.m.Label({
text: "{path: 'status', formatter: 'util.Formatter.statusState'}"
}), new sap.m.Label({
text: "{path: 'limit', formatter: 'util.Formatter.price'} EUR"
}), new sap.m.Label({
text: "{path: 'price', formatter: 'util.Formatter.price'} EUR"
})
]
});
/* table data & model */
var data = {
navigation: [{
name: "Headphone",
status: "A",
limit: 19.99,
price: 12.99
}, {
name: "Mouse Pad",
status: "A",
limit: 5.99,
price: 3.99
}, {
name: "Monitor",
status: "O",
limit: 59.99,
price: 45.99
}, {
name: "Backpack",
status: "A",
limit: 119.99,
price: 79.99
}, {
name: "Printer",
status: "D",
limit: 89.99,
price: 49.99
}, {
name: "Optic Mouse",
status: "D",
limit: 39.99,
price: 15.99
}, {
name: "Dock Station",
status: "D",
limit: 89.99,
price: 55.99
}]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(data);
table.setModel(oModel);
table.bindAggregation("items", "/navigation", template);
/* sort item text model (CSN issue)*/
var dataI18n = {
I18N_NAME: "Name Sorter",
I18N_STATUS: "Status Sorter",
I18N_VALUE: "Value Sorter",
I18N_PRICE: "Price Sorter"
};
var oModel18n = new sap.ui.model.json.JSONModel();
oModel18n.setData(dataI18n);
/********************************************************
* Dialog grouping functions and custom filter controls *
********************************************************/
/* custom grouping functions */
jQuery.sap.declare("util.Formatter");
util.Grouper = {
name: function (oContext) { // take first 3 letters of name
return oContext.getProperty("name").toString().substring(0, 3);
},
value: function (oContext) { // default grouping function using path string values
return oContext.getProperty("limit").toString();
},
price: function (oContext) { // use price to sort in categories (cheap / medium / expensive)
var price = parseInt(oContext.getProperty("price"), 10),
key,
text;
if (price < 20) {
key = "cheap";
text = "Really cheap (<20)";
} else if (price < 40) {
key = "medium";
text = "Normal (<40)";
} else {
key = "expensive";
text = "Totally overpriced (other)";
}
return {
key: key,
text: text
};
}
};
/* definition of a custom control and a callback that returns filters for the control */
var customPriceFilter = new sap.m.VBox({
items: [
new sap.m.Label("minLabel", {
design: sap.m.LabelDesign.Bold,
text: "Minimum price:",
labelFor: "minSlider"
}),
new sap.m.Slider("minSlider", {
value: 0,
min: 0,
max: 100,
step: 10,
progress: true,
liveChange: function (oEvent) {
// update labels and filter item (is cloned in several dialogs)
// we use some internal logic to get the dialog instance and the filter instance from within the control
// if the control is not cloned, access the dialog and the filter by id directly
var source = oEvent.getSource(),
vsd = sap.ui.getCore().byId(source.getParent().getParent().getId().substr(0,4)),
filters = vsd.getFilterItems(),
customFilter,
i = 0;
// update label
source.getParent().getItems()[0].setText("Minimum price >= " + oEvent.getParameter("value"));
// update filter
// this functionality only needed because custom control is cloned for this test page
// if you don't have cloned controls you can directly access them by id and set/reset the values
for(; i < filters.length; i++) {
if(filters[i] instanceof sap.m.ViewSettingsCustomItem && filters[i].getKey() === "myPriceFilter") {
customFilter = filters[i];
break;
}
}
if(customFilter) {
if(oEvent.getParameter("value") !== 0 || source.getParent().getItems()[3].getValue() !== 100) {
customFilter.setSelected(true);
customFilter.setFilterCount(1);
} else {
customFilter.setSelected(false);
customFilter.setFilterCount(0);
}
}
}
}),
new sap.m.Label("maxLabel", {
design: sap.m.LabelDesign.Bold,
text: "Maximum price:",
labelFor: "maxSlider"
}),
new sap.m.Slider("maxSlider", {
value: 100,
min: 0,
max: 100,
step: 10,
progress: true,
liveChange: function (oEvent) {
// update labels and filter item (is cloned in several dialogs)
// we use some internal logic to get the dialog instance and the filter instance from within the control
// if the control is not cloned, access the dialog and the filter by id directly
var source = oEvent.getSource(),
vsd = sap.ui.getCore().byId(source.getParent().getParent().getId().substr(0,4)),
filters = vsd.getFilterItems(),
customFilter,
i = 0;
// update label
source.getParent().getItems()[2].setText("Maximum price <= " + oEvent.getParameter("value"));
// update filter
// this functionality only needed because custom control is cloned for this test page
// if you don't have cloned controls you can directly access them by id and set/reset the values
for(; i < filters.length; i++) {
if(filters[i] instanceof sap.m.ViewSettingsCustomItem && filters[i].getKey() === "myPriceFilter") {
customFilter = filters[i];
break;
}
}
if(customFilter) {
if(oEvent.getParameter("value") !== 100 || source.getParent().getItems()[1].getValue() !== 0) {
customFilter.setSelected(true);
customFilter.setFilterCount(1);
} else {
customFilter.setSelected(false);
customFilter.setFilterCount(0);
}
}
}
})
]
}).addStyleClass("customPriceFilter");
var customPriceCallback = function (oControl) {
var aFilters = [],
aItems = oControl.getItems();
aFilters.push(new sap.ui.model.Filter('price', sap.ui.model.FilterOperator.BT, aItems[1].getValue(), aItems[3].getValue()));
return aFilters;
};
var customPriceReset = function (oEvent) {
var source = oEvent.getSource(),
filters = source.getFilterItems(),
customControl,
customFilter,
i = 0;
// this functionality only needed because custom control is cloned for this test page
// if you don't have cloned controls you can directly access them by id and set/reset the values
for(; i < filters.length; i++) {
if(filters[i] instanceof sap.m.ViewSettingsCustomItem && filters[i].getKey() === "myPriceFilter") {
customFilter = filters[i];
customControl = customFilter.getCustomControl();
break;
}
}
if(customFilter) {
customFilter.setSelected(false);
customFilter.setFilterCount(0);
}
if(customControl) {
customControl.getItems()[0].setText("Minimum price:");
customControl.getItems()[1].setValue(0);
customControl.getItems()[2].setText("Maximum price:");
customControl.getItems()[3].setValue(100);
}
};
var customPriceCancel = customPriceReset;
/* definition of preset filters */
var presetFilters1 = [
new sap.ui.model.Filter("limit", sap.ui.model.FilterOperator.BT, 10, 100),
new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, "o"),
new sap.ui.model.Filter("status", sap.ui.model.FilterOperator.EQ, "D")
];
var presetFilters2 = [
new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains, "e"),
new sap.ui.model.Filter("status", sap.ui.model.FilterOperator.EQ, "A")
];
var presetFilters3 = new sap.ui.model.Filter("price", sap.ui.model.FilterOperator.GT, 50);
/********************************
* ViewSettingsDialog scenarios *
********************************/
/* Example 1) Full-blown view settings dialog with all 3 tabs
- Sort / Group / Filter data is not interpreted
- Data is set by the selected flag on the ViewSettingsFilterItem
Note: We strongly recommend to use the custom data method to define
all sorters and filters with the ViewSettingsItem */
var vsd1 = new sap.m.ViewSettingsDialog("vsd1", {
confirm: function (oEvent) {
var p = oEvent.getParameters(),
oSorter,
oGrouper,
aFilters,
oCallback,
aTableSorters = [],
aTableFilters = [],
i = 0;
// 1) fetch and adjust grouper (set group order)
if (p.groupItem) {
oGrouper = p.groupItem.getCustomData()[0].getValue();
if (oGrouper) {
oGrouper.bDescending = p.groupDescending;
aTableSorters.push(oGrouper);
}
}
// 2) fetch and adjust sorter (set sort order)
if (p.sortItem) {
oSorter = p.sortItem.getCustomData()[0].getValue();
if (oSorter) {
oSorter.bDescending = p.sortDescending;
aTableSorters.push(oSorter);
}
}
// 3) filtering (either preset filters or standard/custom filters)
if (p.presetFilterItem) {
aFilters = p.presetFilterItem.getCustomData()[0].getValue();
if (aFilters) {
// the filter could be an array of filters or a single filter so we transform it to an array
if (!Array.isArray(aFilters)) {
aFilters = [aFilters];
}
aTableFilters = aTableFilters.concat(aFilters);
}
} else { // standard/custom filters
for (; i < p.filterItems.length; i++) {
if (p.filterItems[i] instanceof sap.m.ViewSettingsCustomItem) { // custom control filter
oCallback = p.filterItems[i].getCustomData()[0].getValue();
aFilters = oCallback.apply(this, [p.filterItems[i].getCustomControl()]);
if (aFilters) {
// the filter could be an array of filters or a single filter so we transform it to an array
if (!Array.isArray(aFilters)) {
aFilters = [aFilters];
}
aTableFilters = aTableFilters.concat(aFilters);
}
} else if (p.filterItems[i] instanceof sap.m.ViewSettingsItem) { // standard filter
aFilters = p.filterItems[i].getCustomData()[0].getValue();
if (aFilters) {
// the filter could be an array of filters or a single filter so we transform it to an array
if (!Array.isArray(aFilters)) {
aFilters = [aFilters];
}
aTableFilters = aTableFilters.concat(aFilters);
}
}
}
}
// apply sorters & filters to the table binding
table.getBinding("items").sort(aTableSorters);
table.getBinding("items").filter(aTableFilters);
// update table info bar text (show only if we have a text & set text to label)
table.getInfoToolbar().setVisible(!!p.filterString);
table.getInfoToolbar().getContent()[0].setText(p.filterString);
// show event parameters in debug output
debug.setValue("Selected options for view settings dialog \"" + this.getId() + "\":\n" +
"sortItem: " + (p.sortItem ? p.sortItem.getText() : "null") + "\n" +
"sortOrder: " + (p.sortDescending ? "Descending" : "Ascending") + "\n" +
"groupItem: " + (p.groupItem ? p.groupItem.getText() : "null") + "\n" +
"groupOrder: " + (p.groupDescending ? "Descending" : "Ascending") + "\n" +
"presetFilterItem: " + (p.presetFilterItem ? p.presetFilterItem.getText() : "null") + "\n" +
"filterItems: " + debugSelectedFilterItems(p.filterItems) + "\n" +
"filterKeys: " + JSON.stringify(p.filterKeys) + "\n" +
"filterString: " + p.filterString + "\n" +
"composed sorters: " + JSON.stringify(aTableSorters) + "\n" +
"composed filters: " + JSON.stringify(aTableFilters)
);
}
}).addStyleClass("sapUiNoContentPadding");;
vsd1.setSortDescending(false);
vsd1.setGroupDescending(true);
vsd1.setModel(oModel18n, "i18n");
// init sorting (with simple sorters as custom data for all fields)
vsd1.addSortItem(new sap.m.ViewSettingsItem({
key: "myNameSorter",
text: "{i18n>/I18N_NAME}",
selected: true,
customData: new sap.ui.core.CustomData({
key: "sorter",
value: new sap.ui.model.Sorter("name", false)
})
}));
vsd1.addSortItem(new sap.m.ViewSettingsItem({
key: "myStatusSorter",
text: "{i18n>/I18N_STATUS}",
customData: new sap.ui.core.CustomData({
key: "sorter",
value: new sap.ui.model.Sorter("status", false)
})
}));
vsd1.addSortItem(new sap.m.ViewSettingsItem({
key: "myValueSorter",
text: "{i18n>/I18N_VALUE}",
customData: new sap.ui.core.CustomData({
key: "sorter",
value: new sap.ui.model.Sorter("limit", false)
})
}));
vsd1.addSortItem(new sap.m.ViewSettingsItem({
key: "myPriceSorter",
text: "{i18n>/I18N_PRICE}",
customData: new sap.ui.core.CustomData({
key: "sorter",
value: new sap.ui.model.Sorter("price", false)
})
}));
// init grouping (some simple sorters with default grouping and some with a custom grouping)
vsd1.addGroupItem(new sap.m.ViewSettingsItem({
key: "myNameGrouper",
text: "Name",
customData: new sap.ui.core.CustomData({
key: "sorter",
value: new sap.ui.model.Sorter("name", false, util.Grouper.name)
})
}));
vsd1.addGroupItem(new sap.m.ViewSettingsItem({
key: "myStatusGrouper",
text: "Status",
selected: true,
customData: new sap.ui.core.CustomData({
key: "sorter",
value: new sap.ui.model.Sorter("status", false, true)
})
}));
vsd1.addGroupItem(new sap.m.ViewSettingsItem({
key: "myValueGrouper",
text: "Value",
customData: new sap.ui.core.CustomData({
key: "sorter",
value: new sap.ui.model.Sorter("limit", false, util.Grouper.value)
})
}));
vsd1.addGroupItem(new sap.m.ViewSettingsItem({
key: "myPriceGrouper",
text: "Price",
customData: new sap.ui.core.CustomData({
key: "sorter",
value: new sap.ui.model.Sorter("price", false, util.Grouper.price)
})
}));
vsd1.attachResetFilters(customPriceReset); // reset function to reset control when the reset button was pressed
vsd1.attachCancel(customPriceCancel); // reset function to reset control when the cancel button was pressed
// preset filters
vsd1.addPresetFilterItem(new sap.m.ViewSettingsItem({
key: "myPresetFilter1",
text: "A very complex filter",
customData: new sap.ui.core.CustomData({
key: "filter",
value: presetFilters1
})
}));
vsd1.addPresetFilterItem(new sap.m.ViewSettingsItem({
key: "myPresetFilter2",
text: "Ridiculously complex filter",
customData: new sap.ui.core.CustomData({
key: "filter",
value: presetFilters2
})
}));
vsd1.addPresetFilterItem(new sap.m.ViewSettingsItem({
key: "myPresetFilter3",
text: "Expensive stuff",
customData: new sap.ui.core.CustomData({
key: "filter",
value: presetFilters2
})
}));
/* Example 2) Full-blown view settings dialog with all 3 tabs
- Sort / Group / Filter data is compiled in the event based on the item keys
- Dialog state is set by API after filling the aggregations
Note: We strongly recommend to use the custom data method from example 1)
However if you prefer working with keys and setting the filters in the
event method here is an example how to do so */
var vsd2 = new sap.m.ViewSettingsDialog("vsd2", {
confirm: function (oEvent) {
var p = oEvent.getParameters(),
sSortPath = null,
oSorter,
sGroupPath = null,
oGroupFunction = null,
oGrouper,
aFilters = null,
oCallback = null,
aTableSorters = [],
aTableFilters = [],
i = 0;
// 1) create grouper based on key
if (p.groupItem) {
// decide based on id
switch (p.groupItem.getKey()) {
case "myNameGrouper": sGroupPath = "name"; oGroupFunction = util.Grouper.name; break;
case "myStatusGrouper": sGroupPath = "status"; break;
case "myValueGrouper": sGroupPath = "limit"; oGroupFunction = util.Grouper.value; break;
case "myPriceGrouper": sGroupPath = "price"; oGroupFunction = util.Grouper.price; break;
}
// create grouper
if (sGroupPath) {
oGrouper = new sap.ui.model.Sorter(sGroupPath, p.groupDescending, (oGroupFunction ? oGroupFunction : true)); // true is default sorter
aTableSorters.push(oGrouper);
}
}
// 2) create sorter based on key
if (p.sortItem) {
// decide based on id
switch (p.sortItem.getKey()) {
case "myNameSorter": sSortPath = "name"; break;
case "myStatusSorter": sSortPath = "status"; break;
case "myValueSorter": sSortPath = "limit"; break;
case "myPriceSorter": sSortPath = "price"; break;
}
// create sorter
if (sSortPath) {
oSorter = new sap.ui.model.Sorter(sSortPath, p.sortDescending);
aTableSorters.push(oSorter);
}
}
// 3) filtering (either preset filters or standard/custom filters)
if (p.presetFilterItem) {
// decide based on id
switch (p.presetFilterItem.getKey()) {
case "myPresetFilter1": aFilters = presetFilters1; break;
case "myPresetFilter2": aFilters = presetFilters2; break;
case "myPresetFilter3": aFilters = presetFilters3; break;
}
// add filters
if (aFilters) {
// the filter could be an array of filters or a single filter so we transform it to an array
if (!Array.isArray(aFilters)) {
aFilters = [aFilters];
}
aTableFilters = aTableFilters.concat(aFilters);
}
} else { // standard/custom filters
for (; i < p.filterItems.length; i++) {
if (p.filterItems[i] instanceof sap.m.ViewSettingsCustomItem) { // custom control filter
// decide based on id
switch (p.filterItems[i].getKey()) {
case "myPriceFilter": oCallback = customPriceCallback; break;
}
// call callback and add filters
if (oCallback) {
aFilters = oCallback.apply(this, [p.filterItems[i].getCustomControl()]);
if (aFilters) {
// the filter could be an array of filters or a single filter so we transform it to an array
if (!Array.isArray(aFilters)) {
aFilters = [aFilters];
}
aTableFilters = aTableFilters.concat(aFilters);
}
}
} else if (p.filterItems[i] instanceof sap.m.ViewSettingsItem) { // standard filter
// decide based on id
switch (p.filterItems[i].getKey()) {
case "name1": aFilters = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.EQ, "Headphone"); break;
case "name2": aFilters = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.EQ, "Mouse Pad"); break;
case "name3": aFilters = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.EQ, "Monitor"); break;
case "name4": aFilters = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.EQ, "Backpack"); break;
case "name5": aFilters = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.EQ, "Printer"); break;
case "name6": aFilters = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.EQ, "Optic Mouse"); break;
case "name7": aFilters = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.EQ, "Dock Station"); break;
case "status1": aFilters = new sap.ui.model.Filter("status", sap.ui.model.FilterOperator.EQ, "A"); break;
case "status2": aFilters = new sap.ui.model.Filter("status", sap.ui.model.FilterOperator.EQ, "O"); break;
case "status3": aFilters = new sap.ui.model.Filter("status", sap.ui.model.FilterOperator.EQ, "D"); break;
case "value1": aFilters = new sap.ui.model.Filter("limit", sap.ui.model.FilterOperator.LT, 10); break;
case "value2": aFilters = new sap.ui.model.Filter("limit", sap.ui.model.FilterOperator.BT, 10, 30); break;
case "value3": aFilters = new sap.ui.model.Filter("limit", sap.ui.model.FilterOperator.BT, 30, 50); break;
case "value4": aFilters = new sap.ui.model.Filter("limit", sap.ui.model.FilterOperator.BT, 50, 70); break;
case "value5": aFilters = new sap.ui.model.Filter("limit", sap.ui.model.FilterOperator.GT, 70); break;
}
// add filters
if (aFilters) {
// the filter could be an array of filters or a single filter so we transform it to an array
if (!Array.isArray(aFilters)) {
aFilters = [aFilters];
}
aTableFilters = aTableFilters.concat(aFilters);
}
}
}
}
// apply sorters & filters to the table binding
table.getBinding("items").sort(aTableSorters);
table.getBinding("items").filter(aTableFilters);
// update table info bar text (show only if we have a text & set text to label)
table.getInfoToolbar().setVisible(!!p.filterString);
table.getInfoToolbar().getContent()[0].setText(p.filterString);
// show event parameters in debug output
debug.setValue("Selected options for view settings dialog \"" + this.getId() + "\":\n" +
"sortItem: " + (p.sortItem ? p.sortItem.getText() : "null") + "\n" +
"sortOrder: " + (p.sortDescending ? "Descending" : "Ascending") + "\n" +
"groupItem: " + (p.groupItem ? p.groupItem.getText() : "null") + "\n" +
"groupOrder: " + (p.groupDescending ? "Descending" : "Ascending") + "\n" +
"presetFilterItem: " + (p.presetFilterItem ? p.presetFilterItem.getText() : "null") + "\n" +
"filterItems: " + debugSelectedFilterItems(p.filterItems) + "\n" +
"filterKeys: " + JSON.stringify(p.filterKeys) + "\n" +
"filterString: " + p.filterString + "\n" +
"composed sorters: " + JSON.stringify(aTableSorters) + "\n" +
"composed filters: " + JSON.stringify(aTableFilters)
);
},
filterSearchOperator: sap.m.StringFilterOperator.Contains
});
// init sorting (with simple sorters as custom data for all fields)
vsd2.addSortItem(new sap.m.ViewSettingsItem({
key: "myNameSorter",
text: "Please fill in your name, middle name and Last name",
wrapping: true
}));
vsd2.addSortItem(new sap.m.ViewSettingsItem({
key: "myStatusSorter",
text: "Status"
}));
vsd2.addSortItem(new sap.m.ViewSettingsItem({
key: "myValueSorter",
text: "Value"
}));
vsd2.addSortItem(new sap.m.ViewSettingsItem({
key: "myPriceSorter",
text: "Price"
}));
// init grouping (some simple sorters with default grouping and some with a custom grouping)
vsd2.addGroupItem(new sap.m.ViewSettingsItem({
key: "myNameGrouper",
text: "Name"
}));
vsd2.addGroupItem(new sap.m.ViewSettingsItem({
key: "myStatusGrouper",
text: "Status"
}));
vsd2.addGroupItem(new sap.m.ViewSettingsItem({
key: "myValueGrouper",
text: "Value"
}));
vsd2.addGroupItem(new sap.m.ViewSettingsItem({
key: "myPriceGrouper",
text: "Price"
}));
vsd2.addFilterItem(new sap.m.ViewSettingsFilterItem({
key: "myNameFilter",
text: "Name",
items: [
new sap.m.ViewSettingsItem({
key: "name1",
text: "Headphone"
}),
new sap.m.ViewSettingsItem({
key: "name2",
text: "Mousepad"
}),
new sap.m.ViewSettingsItem({
key: "name3",
text: "Monitor"
}),
new sap.m.ViewSettingsItem({
key: "name4",
text: "Backpack"
}),
new sap.m.ViewSettingsItem({
key: "name5",
text: "Printer"
}),
new sap.m.ViewSettingsItem({
key: "name6",
text: "Optic Mouse"
}),
new sap.m.ViewSettingsItem({
key: "name7",
text: "Dock Station"
})
]
}));
vsd2.addFilterItem(new sap.m.ViewSettingsFilterItem({
key: "myStatusFilter",
text: "Status",
items: [
new sap.m.ViewSettingsItem({
key: "status1",
text: "Approved"
}),
new sap.m.ViewSettingsItem({
key: "status2",
text: "Open"
}),
new sap.m.ViewSettingsItem({
key: "status3",
text: "Denied"
})
]
}));
vsd2.addFilterItem(new sap.m.ViewSettingsFilterItem({
key: "myValueFilter",
text: "Value",
items: [
new sap.m.ViewSettingsItem({
key: "value1",
text: "< 10 EUR"
}),
new sap.m.ViewSettingsItem({
key: "value2",
text: "10 - 30 EUR"
}),
new sap.m.ViewSettingsItem({
key: "value3",
text: "30 - 50 EUR"
}),
new sap.m.ViewSettingsItem({
key: "value4",
text: "50 - 70 EUR"
}),
new sap.m.ViewSettingsItem({
key: "value5",
text: "> 70 EUR"
})
]
}));
// custom price control filter
vsd2.addFilterItem(new sap.m.ViewSettingsCustomItem({
key: "myPriceFilter",
text: "Price",
customControl: customPriceFilter.clone()
}));
vsd2.attachResetFilters(customPriceReset); // reset function to reset control when the reset button was pressed
vsd2.attachCancel(customPriceCancel); // reset function to reset control when the cancel button was pressed
/* set dialog state (solely by API instead of selected flag) */
vsd2.setSelectedSortItem(vsd2.getSortItems()[0]);
vsd2.setSortDescending(true);
vsd2.setSelectedGroupItem(vsd2.getGroupItems()[1]);
vsd2.setGroupDescending(true);
vsd2.setSelectedFilterKeys({
"name1": true,
"name2": true,
"name5": true,
"name6": true,
"status1": true,
"status2": true,
"status3": true,
"value3": true
});
/* Example 3) Full-blown view settings dialog with all 3 tabs
- Sort / Group / Filter data is not interpreted
- Data is set by the selected flag on the ViewSettingsFilterItem */
var vsd3 = new sap.m.ViewSettingsDialog("vsd3", {
confirm: function (oEvent) {
var p = oEvent.getParameters();
sap.m.MessageBox.alert("You could now do something with the result!");
// update table info bar text (show only if we have a text & set text to label)
table.getInfoToolbar().setVisible(!!p.filterString);
table.getInfoToolbar().getContent()[0].setText(p.filterString);
// show event parameters in debug output
debug.setValue("Selected options for view settings dialog \"" + this.getId() + "\":\n" +
"sortItem: " + (p.sortItem ? p.sortItem.getText() : "null") + "\n" +
"sortOrder: " + (p.sortDescending ? "Descending" : "Ascending") + "\n" +
"groupItem: " + (p.groupItem ? p.groupItem.getText() : "null") + "\n" +
"groupOrder: " + (p.groupDescending ? "Descending" : "Ascending") + "\n" +
"presetFilterItem: " + (p.presetFilterItem ? p.presetFilterItem.getText() : "null") + "\n" +
"filterItems: " + debugSelectedFilterItems(p.filterItems) + "\n" +
"filterKeys: " + JSON.stringify(p.filterKeys) + "\n" +
"filterString: " + p.filterString
);
}
});
// init sorting (with simple sorters as custom data for all fields)
vsd3.addSortItem(new sap.m.ViewSettingsItem({
key: "myNameSorter",
text: "Name",
selected: true
}));
vsd3.addSortItem(new sap.m.ViewSettingsItem({
key: "myStatusSorter",
text: "Status"
}));
vsd3.addSortItem(new sap.m.ViewSettingsItem({
key: "myValueSorter",
text: "Value"
}));
vsd3.addSortItem(new sap.m.ViewSettingsItem({
key: "myPriceSorter",
text: "Price"
}));
// init grouping (some simple sorters with default grouping and some with a custom grouping)
vsd3.addGroupItem(new sap.m.ViewSettingsItem({
key: "myNameGrouper",
text: "Name"
}));
vsd3.addGroupItem(new sap.m.ViewSettingsItem({
key: "myStatusGrouper",
text: "Status",
selected: true
}));
vsd3.addGroupItem(new sap.m.ViewSettingsItem({
key: "myValueGrouper",
text: "Value"
}));
vsd3.addGroupItem(new sap.m.ViewSettingsItem({
key: "myPriceGrouper",
text: "Price"
}));
vsd3.addFilterItem(new sap.m.ViewSettingsFilterItem({
key: "myNameFilter",
text: "Name",
items: [
new sap.m.ViewSettingsItem({
key: "name1",
text: "Headphone",
selected: true
}),
new sap.m.ViewSettingsItem({
key: "name2",
text: "Mousepad",
selected: true
}),
new sap.m.ViewSettingsItem({
key: "name3",
text: "Monitor"
}),
new sap.m.ViewSettingsItem({
key: "name4",
text: "Backpack"
}),
new sap.m.ViewSettingsItem({
key: "name5",
text: "Printer",
selected: true
}),
new sap.m.ViewSettingsItem({
key: "name6",
text: "Optic Mouse",
selected: true
}),
new sap.m.ViewSettingsItem({
key: "name7",
text: "Dock Station"
})
]
}));