Clarification on usage of field().focus()

Clarification on usage of field().focus()

Korben DallasKorben Dallas Posts: 5Questions: 2Answers: 0

I have a Datatable editor page with 2 columns of data. The first column contains unique labels and is used also as the rowId and idSrc and it is not editable. The second column contains the text descriptions associated with each label and is setup to be inline editable.

label_key desc_text
a_unique_key The editable text associated with: a_unique_key
another_key text associated with another_key (this is my focus target )
yet_another more editable text

My editor fields: are setup as follows

fields: [ {
        label: "Unique Key:",
        name: "label_key"
    }, {
        label: "Description:",
        name: "desc_text",
        type: "textarea"
    }
]

My Datatables columns are setup as follows:

columns: [
    {
        data: null,
        defaultContent: "",
        className: "select-checkbox",
        orderable: false,
        "width": "10%",
    },
    { data: "label_key", "width": "25%" },
    { data: "desc_text", className: "editable" }
],

I want to be able to programmatically give focus to a specific field in the desc_text column (the second one for example) and it seems I need to use field().focus() to do that. What I cannot wrap my head around is what I need to use as the "field_name" to target given the concise example below from the docs:

 editor.field( 'Field_Name_1' ).focus();

Any guidance or suggestions are appreciated.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,795Questions: 1Answers: 10,115 Site admin
    Answer ✓

    Hi,

    field().focus() is used to focus on a specific field in the form. From your fields array that will be either label_key or desc_text.

    I think the missing ingredient here is that you need to trigger editing on one of the rows in the DataTable before you can focus on a field (since that field is shared between all rows, depending on which is being edited).

    Alternative, if you want an Excel like focus, you could use KeyTable and its cell().focus() method.

    Allan

This discussion has been closed.