How to change autoComplete "source" table dynamically

How to change autoComplete "source" table dynamically

mikewang888mikewang888 Posts: 1Questions: 1Answers: 0

Hi,
I want to user your autoComplete feather in your Editor.
I tried with this example "https://editor.datatables.net/examples/simple/inTableControls.html"
By adding "jquery-ui-1.12.1/jquery-ui.css", "jquery-ui-1.12.1/jquery-ui.js" and "editor.autoComplete.js" to its header,
and also adding
"label": "Position:",
"name": "position" ,
"type": "autoComplete",
"opts": { "source": [ 'CEO1', 'Accountant1', 'Doctor1'] }
in "fields:" section of the "editor = new $.fn.dataTable.Editor(...)" creation procedure, the feature worked fine.

The problem is that I couldn't find a way to update or change the above "source" table to a new table like [ 'CEO2', 'Accountant2', 'Doctor2'] .
After the Editor's creation, I tried to use the following js script to change "source" to a new table
editor.s.fields.position.s.opts.opts.source = [ 'CEO2', 'Accountant2', 'Doctor2'];
By opening "Create new record" window, your Editor still use the old table [ 'CEO1', 'Accountant1', 'Doctor1'] for autoComplete prompting.
Do you know how to change the "source" table or the prompting table dynamically? There are quite a lot of reasons to do so.

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Hi,

    The jQuery UI AutoComplete plug-in for Editor has an update() method available for it (see field().update()) which can be used to update the list of options .e.g.:

    editor.field('position').update(
      [ 'CEO2', 'Accountant2', 'Doctor2']
    );
    

    Regards,
    Allan

This discussion has been closed.