Advanced Configuration of Popup Selectors

Combo, richselect, multiselect and multicombo controls can be highly customized because they are comprised of the following components:

  • Webix text input that can be either editable (for combos) or non-editable (for selects);
  • Webix list from which templating and loading rules, item sizes and look-and-feel are taken;
  • Webix popup from which popup size and behavior are taken.

The combination of list and popup is called suggest list (described in detail separately). Here we will have a look at extra configuration possibilities of suggest-based controls.

Advanced Configuration

Normally, we define select options as array or data source:

Short notation

{ view:"combo", options:[] }
{ view:"combo", options:"mydata.php"}

A suggest list of a default type will be attached. It will feature default template, size and filtering(for editable inputs). If you need to customize these things, you should use the extended configuration.

Extended notation

{ view:"combo", options:{
    view:"suggest", //optional
    filter:function(item, value){ ...},
    body:{ //list configuration
        view:"list", //optional

Related sample:  Advanced options for select controls ('combo' and 'richselect')

As you can see, options attribute can be used as object that houses suggest configuration and list settings in its body.

Changing Option Template

Option data may contain any properties instead of (in addition to) default id-value pairs (still, id attribute is mandatory).

{ view:"combo",  value:2, options:{
       { id:1, name:"Banana" },
       { id:2, name:"Papaya" }

Extra text or HTML can be added:

{ view:"combo",  value:2, options:{
    template:"Extra #value#",
       { id:1, value:"Banana" },
       { id:2, value:"Papaya" }

Options data may as well contain multi-line text with html tags. In this case, the height of a parent component (here:toolbar) should be increased:

{ view:"richselect",
    { id:1, value:"Some long multi line content <ul><li>item1 <li> item 2</ul>"}, 
    { id:2, value:"Papaya"  }

Related sample:  Select Boxes

Changing Filtering Pattern

When a custom template is used for a combo box filtering should be redefined as well, since by default combo popup is filtered by value property.

Options attribute houses configuration of a suggest list in use while its body attribute houses a popup list:

view:"combo", value:1, options:{
    filter:function(item, value){
             return true;
        return false;
           { id:1, name:"Banana"},
           { id:2, name:"Papaya"}

Filtering is applied only in case the suggest list is combined with editable inputs - combo and multicombo.

Server-Side Options

The easiest way to load options from server is to set a link to the necessary script right in the options attribute:

view:"richselect", value:"2", options: "server/data.json"

For extra customization, see below how to define options dynamically.

Getting Popup and List objects

The controls feature special API to work with their parts:

var popup = richselect.getPopup(); //popup object
var list = richselect.getPopup().getList(); // list object

Defining Options Dynamically

Defining options data through the control:

Options can be redefined like any other property:

combo.define("options", [ {id:1, value:"Apple"}, {id:2, value:"Banana"} ]);

Parsing options into a popup list

Options are parsed to popup list under Webix data loading rules:

var list = $$("combo1").getPopup().getList();
var new_options = [
      { id:1, name:"Germany"},
      { id:2, name:"Great Britain"}

Options can be loaded by Ajax as well:

webix.ajax().get("server/data.php", function(text, data){
    var options = data.json();
    var list = $$("combo1").getPopup().getList();

Loading options into a popup list

Options are loaded to popup list under Webix data loading rules:

var list = $$("richselect2").getPopup().getList();

Syncing Options with a DataCollection

Options list can be synchronized with either other component data or Datacollection data:

// pushes the specified data into richselect popup 

Related sample:  Get Popup View

Data syncing is described in the related article.

Attaching Events within a Suggest List

You can attach functions to list under the common Events Handling pattern:

view:"combo", value:1, options:{
           { id:1, value:"Banana"},
           { id:2, value:"Papaya"},
           { id:3, value:"Apple"}
               webix.message("Clicked: "+this.getItem(id).value);

Still, to catch changes in the combo/richselect, it's better to use the related onChange event.

Sizing and Positioning

The dimensions of a popup list as well as its position in relation to a master control can be customized via suggest/options configuration object.

view:"combo", options:{

Read more about it in the corresponding documentation article.

Changing Suggest Type

Be careful while experimenting with this feature - suggest lists differ in functionality.

By default, multiple-choice controls, e.g. multiselect use a checksuggest for storing options:

{ view:"multiselect", options:[
    { id:1, value:"Alex Brown" },
    { id:2, value:"Dan Simons" }

If you want to use a multisuggest for these needs, use extended configuration and specify view name:

{ view:"multiselect",  options:{
    buttonText:"Approve", //"Select" by default
        { id:1, value:"Alex Brown" },
        { id:2, value:"Dan Simons" }                        

Related sample:  Multi-select input

Read more about advanced suggest lists.

Back to top