Since 4.3
The DoubleList control is based on Layout and includes features peculiar to the List widget and the Select control. It presents data items in two lists: the left list contains all available items and the right one displays selected items.
There's a variety of ways to select items. You can use the related buttons, drag-n-drop items or simply double click on the necessary item.
webix.ui({
view:"dbllist",
list:{ autoheight: true },
labelLeft:"Available screens",
labelRight:"Selected",
data:[
{id:"1", value:"Contacts"},
{id:"2", value:"Products"},
{id:"3", value:"Reports"},
{id:"4", value:"Customers"},
{id:"5", value:"Deals"}
]
});
Related sample: Double List as Form Input
The default DoubleList buttons look as follows:
You can define custom buttons for your interface by using the buttons property. There are two ways to customize the buttons' appearance:
webix.ui({
view:"dbllist",
buttons:"<button class='dbllist_button'>Select</button>
<button class='dbllist_button'>Remove</button>"
data:[
{id:"1", value:"Guest"},
{id:"2", value:"Member"}
]
});
webix.ui({
view:"dbllist",
list:{
autoheight: true,
select: false,
template:function(obj, common){
var dir = (common.id === "left" ? "right" : "left");
return obj.value + "<span class='select_one webix_icon fa-arrow-"+dir+"'></span>"
},
onClick:{
"select_one":function(e, id){
var mode = this.config.$id === "left";
this.getTopParentView().select(id, mode);
return false;
}
}
},
buttons:false,
data:[
{id:"1", value:"Contacts"},
{id:"2", value:"Products"}
]
});
Related sample: Double List : Custom Buttons
You can specify what items should be selected (placed to the right list) initially. For this, you should use the value property and IDs of the necessary items.
It is possible to set the IDs either as a string or as an array:
webix.ui({
view:"dbllist",
value:"1,2",
data:[
{id:"1", value:"Guest"},
{id:"2", value:"Member"},
{id:"3", value:"Moderator"}
]
});
You can also select items via calling the select method. It can both select the specified items (move them to the right list) or return them back to the left list.
The method takes two parameters:
// selects items with ids 3,4 to the right list
$$("dbl1").select([3,4],true);
// returns items with ids 3,4 back to the left list
$$("dbl1").select([3,4],false);
There's a pair of methods that allow specifiying the values of items to select and getting the list of selected items.
The setValue() method defines the item(s) that should be selected (moved to the right list). It takes the items IDs as a string or as an array:
webix.ui({
view:"dbllist",
id:"dbl1",
data:[
{id:"1", value:"Guest"},
{id:"2", value:"Member"},
{id:"3", value:"Moderator"}
]
});
$$("dbl1").setValue([1,3]);
// or
$$("dbl1").setValue("1,3")
The getValue() method returns the list of selected values:
webix.ui({
view:"dbllist",
id:"dbl1",
value:"1,2",
data:[
{id:"1", value:"Guest"},
{id:"2", value:"Member"},
{id:"3", value:"Moderator"}
]
});
$$("dbl1").getValue(); // returns "1,2"
If you want to configure the lists of DoubleList, you can make use of the list property:
webix.ui({
view:"dbllist",
list:{ height: 200, scroll:false },
data:[
{id:"1", value:"Guest"},
{id:"2", value:"Member"}
]
});
To access the left or right lists separately, you can address to them by IDs. The left list has the ID "left" and the right one - "right", correspondingly.
You can apply the List API to separate lists of the DoubleList control. For example:
$$("$dbllist1").$$("left").disable();
It is possible to get the data of the left or the right list by calling the serialize() method of the related list in the following way:
$$("dbllist").$$("left").data.serialize();
// or
$$("dbllist").$$("right").data.serialize();
This notation will return an array with data of the specified list.
The DoubleList control can be added into a form with the help of the FormInput control.
You need to create an instance of doublelist and put it into the body of the forminput control.
// creating a doublelist view
var list1 = {
view:"dbllist",
data:[
{id:"1", value:"Guest"},
{id:"2", value:"Member"},
{id:"3", value:"Moderator"}
]
};
// adding the doublelist view into the forminput
webix.ui({
view:"form", id:"form1",
rows:[
{ view:"text", label:"User Name", labelAlign:"right", labelWidth: 140 },
{ view:"forminput", name:"access", body:list1, labelWidth: 140,
labelAlign:"right", label:"Access levels" }
]
});
In order to set a value for the doublelist, you should use the setValues method of the Form and refer to the forminput by its name:
// setting value for the doublelist
$$("form1").setValues({
access:"1,2"
});
Related sample: Double List as Form Input