Can I use a select lookup list on two fields?

Can I use a select lookup list on two fields?

Adrian ChallinorAdrian Challinor Posts: 21Questions: 8Answers: 0

My data is coming from Java and is passed to Datatables as data from the ajax call. With the data portion, there is also an options area, with named lists of options in value/label pairs.

I have a data table which contains two fields which are displayed as type:'select' drop downs. Normally I don't have any other fields other then the type. Data tables picks up the lookup options from the name of the field.

This time, these two fields both get their values from the same set of options. I want to avoid passing this down from the sever twice as that is just a horrible hack. It works, but, well, its poor code.

So, is there a way to specific that I want to use the same options list on both fields?

I tried this, but it's not liked at all!

{ label : "Events:", name : "events1", type: "select", options: events}

(ps: if it helps, I will eventually be replacing teh select with the new datatable type, and making this a multiple select. But I have some other issues with the server-side code and editor v2.0.2 - that is another story).

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    Hi Adrian,

    Thanks for the description of the problem. I'm assuming that your Ajax JSON data contains an options object (like in our examples) which is used to populate the list of options? If so, the way that works is that Editor will watch for DataTables Ajax request and find the options object, matching the keys in it to the field names. So in the case of above events1 would be automatically populated.

    If you want to reuse the same options for a second field, you'll need to listen for the same event Editor is (xhr) and use the same options list to populate the second field - e.g.:

    table.on('xhr.dt', function (e, s, json) {
      editor.field('events2').update(json.options.events1);
    });
    

    Regards,
    Allan

This discussion has been closed.