Back to Devexpress

FieldCollection Class

aspnetcore-js-devexpress-dot-richedit-5b1e23cb.md

latest5.7 KB
Original Source

FieldCollection Class

A collection of the Field objects.

Declaration

ts
export class FieldCollection extends Collection<Field>

Inherited Members

count

getByIndex(index)

Inheritance

Collection<T> FieldCollection

Methods

create(position) Method

Creates a new field.

Declaration

ts
create(
    position: number | Interval,
    code?: string
): Field

Parameters

NameTypeDescription
positionnumberInterval

A position in the document or a document interval.

| | code | string |

A field code.

|

Returns

TypeDescription
Field

The newly created field object.

|

Remarks

You can use the create method to create a new field:

  • Specify a document position to insert a field and a field code.

  • Specify a document interval to be wrapped in a new field.

The newly created field has no result value until the field is updated. To update the field, use the UI or call the update or updateAllFields method.

See Also

Common Use Cases: Field

createMergeField(position, name) Method

Creates a new merge field.

Declaration

ts
createMergeField(
    position: number,
    name: string
): Field

Parameters

NameTypeDescription
positionnumber

A position in the document.

| | name | string |

The name of a data source column.

|

Returns

TypeDescription
Field

The newly created field.

|

Remarks

The newly created field has no result value until the field is updated. To update the field, use the UI or call the update or updateAllFields method.

javascript
var subDocument = richEdit.selection.activeSubDocument;
var field = subDocument.fields.createMergeField(richEdit.selection.active, 'City');
field.update(function(self) {
    console.log(subDocument.getText(self.resultInterval)); // returns "<<City>>" 
});

Run Demo: Mail Merge

find(position) Method

Returns a list of fields that traverse the specified position or interval.

Declaration

ts
find(
    position: number | IInterval
): Field[]

Parameters

NameTypeDescription
positionnumberIInterval

A document position or interval.

|

Returns

TypeDescription
Field[]

A list of fields.

|

Remarks

javascript
var subDocument = richEdit.selection.activeSubDocument;
var fields = subDocument.fields.find(richEdit.selection.active);
fields.forEach(function(field) {
    console.log(subDocument.getText(field.interval));
});

showAllFieldCodes Method

Displays field codes in place of the fields in the document.

Declaration

ts
showAllFieldCodes(
    doInAllSubDocuments?: boolean
): void

Parameters

NameTypeDescription
doInAllSubDocumentsboolean

true , to display field codes in all sub-documents, false , to display field codes in the current sub-document only.

|

showAllFieldResults Method

Displays field results in place of the fields in the document.

Declaration

ts
showAllFieldResults(
    doInAllSubDocuments?: boolean
): void

Parameters

NameTypeDescription
doInAllSubDocumentsboolean

true , to display field results in all sub-documents, false , to display field results in the current sub-document only.

|

updateAllFields Method

Updates and displays all field results.

Declaration

ts
updateAllFields(
    callback?: () => void,
    options?: UpdateFieldsOptions
): boolean

Parameters

NameTypeDescription
callback() => void

A function that is called after fields are updated.

| | options | UpdateFieldsOptions |

An object that contains update options.

|

Returns

TypeDescription
boolean

true , if the field has been updated successfully; otherwise, false.

|

Remarks

javascript
var doInAllSubDocuments = true;
var updateTocFields = true;
var options = new DevExpress.RichEdit.UpdateFieldsOptions(doInAllSubDocuments, updateTocFields);
richEdit.document.fields.updateAllFields(function() {
    console.log('Updated');
}, options);

See Also

Common Use Cases: Field