maykinmedia / dual-listbox

A simple dual listbox build in plain Javascript and some simple styling. (no other libraries of frameworks required)

Home Page:https://maykinmedia.github.io/dual-listbox/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to set selected items programmatically

phoarau opened this issue · comments

It is not very clear in the documentation the way to select elements with Javascript.
Here my code

My dual box is working find. MBut I need to select some items after an ajax call.

        scheduleAgentsIds = new DualListbox('#scheduleAgentsIds');
        $.each(team.agents, function (k, v) {
            scheduleAgentsIds.addSelected(v.id);
        });
        scheduleAgentsIds.redraw();

And it does'nt work.

Anyone can help me?

Hello,

You are doing the correct thing. But the addSelected expects the <li> element. This can be selected by the data-id attribute. The data-id is the value of the original select option.

Hope this helps.