Skip to content

NEW since 2023.2.25

Working with field collections AppGiniFields

Get all fields of a DetailView

1
2
3
4
// file: hooks/TABLENAME-dv.js
var dv = AppGiniHelper.dv;
var fields = dv.getFields();
// --> collection containing all supported fields

Get a collection of fields

1
2
3
4
5
6
7
8
9
// 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 .

1
2
3
4
5
6
7
8
// 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[]

1
2
3
4
5
6
7
// 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
// 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

1
2
3
4
5
6
7
8
// 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

1
var f = AppGiniHelper.DV.getFields(["a", "b"]); // --> a,b

Include

collection + single field

1
var f = AppGiniHelper.DV.getFields(["a", "b"]).include("c"); // --> a, b, c

collection + multiple fields

1
var f = AppGiniHelper.DV.getFields(["a", "b"]).include(["c", "d"]); // --> a, b, c, d

collection + collection

1
2
3
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

1
var f = AppGiniHelper.DV.getFields(["a", "b", "c"]).exclude("c"); // --> a, b

collection - multiple fields

1
var f = AppGiniHelper.DV.getFields(["a", "b", "c", "d"]).exclude(["c", "d"]); // --> a, b

collection - collection

1
2
3
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

1
2
var field = AppGiniHelper.DV.getField("a"); // single field
var fields_2 = field.include("b"); // --> collection of a, b 

See also