NEW
since 2023.2.25
Working with field collections AppGiniFields
Get all fields of a DetailView
| // file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
var fields = dv.getFields();
// --> collection containing all supported fields
|
Get a collection of fields
| // file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
// intially set three fields
var fields = dv.getFields(["id", "created_on", "created_by"]);
// --> collection: id, created_on, created_by
// example
fields.hide();
|
Remove fields from an existing field collection
Exclude single field by name
Pass fieldname as string
.
| // file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
// intially set three fields
var fields = dv.getFields(["id", "created_on", "created_by"]);
// --> collection: id, created_on, created_by
var less_fields = fields.exclude("id"); // remove id-field
// --> new collection: created_on, created_by
|
Exclude multiple fields by name
Pass fieldnames as array of strings string[]
| // file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
var all_fields = dv.getFields();
// -> collection of all fields ...
var less_fields = all_fields.exclude(["id", "created_on", "created_by"]); // remove three fields
// --> new collection: all fields WITHOUT id, created_on, created_by
|
Exclude multiple fields collection
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | // file: hooks/TABLENAME-dv.js
var all_fields = AppGiniHelper.DV.getFields();
// --> collection of all fields ...
// initially set two fields
var system_fields = AppGiniHelper.DV.getFields(["onload", "debuglevel"]);
// --> collection: online, debuglevel
// remove field-collection from field-collection
var non_system_fields = all_fields.exclude(system_fields);
// --> new collection: all fields but onload, debuglevel
// work with remaining fields, for example...
non_system_fields.hide();
|
Add fields to an existing field cllection
| // file: hooks/TABLENAME-dv.js
// initially set two fields
var some_fields = AppGiniHelper.DV.getFields(["created_on", "created_by"]);
// --> collection: created_on, created_by
var more_fields = some_fields.include("id"); // add id-field
// --> new collection: created_on, created_by, id
var even_more_fields = some_fields.include(["modified_on", "modified_by"]); // add two fields
// --> new collection: created_on, created_by, id, modified_on, modified_by
|
Create a collection from a single field
| // intially get variable for id-field
var id = AppGiniHelper.DV.getField("id");
// id instanceof AppGiniField
// add two fields.
var fields = id.include(["created_on", "created_by"]);
// --> new collection: id, created_on, created_by
// fields instanceof AppGiniFields
|
Notes
- Both methods,
.exclude(...)
and .include(...)
, return a new (important!) AppGiniFields
-object, holding the configured fields.
- After
exclude
/include
the orginal AppGiniField
- or AppGiniFields
-object will remain unchanged an can still be used.
- Calling
.include()
on an AppGiniField
-object (single field) will return a new AppGiniFields
-object (multiple fields container)
- Calling
.exclude()
on an AppGiniFields
-object resulting in a single field remaining, will always return an AppGiniFields
-object, even if there is only one field left.
This will not return a single-field AppGiniField
-object (single)
Overview
Init collection
| var f = AppGiniHelper.DV.getFields(["a", "b"]); // --> a,b
|
Include
collection + single field
| var f = AppGiniHelper.DV.getFields(["a", "b"]).include("c"); // --> a, b, c
|
collection + multiple fields
| var f = AppGiniHelper.DV.getFields(["a", "b"]).include(["c", "d"]); // --> a, b, c, d
|
collection + collection
| var f1 = AppGiniHelper.DV.getFields(["a", "b"]); // --> a, b
var f2 = AppGiniHelper.DV.getFields(["c", "d"]); // --> c, d
var f = f1.include(f2); // --> a, b, c, d
|
Exclude
collection - single field
| var f = AppGiniHelper.DV.getFields(["a", "b", "c"]).exclude("c"); // --> a, b
|
collection - multiple fields
| var f = AppGiniHelper.DV.getFields(["a", "b", "c", "d"]).exclude(["c", "d"]); // --> a, b
|
collection - collection
| var f1 = AppGiniHelper.DV.getFields(["a", "b", "c", "d"]); // --> a, b, c, d
var f2 = AppGiniHelper.DV.getFields(["c", "d"]); // --> c, d
var f = f1.exclude(f2); // --> a, b
|
Field to collection
| var field = AppGiniHelper.DV.getField("a"); // single field
var fields_2 = field.include("b"); // --> collection of a, b
|
See also