Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery EasyUI Form Plugin - Combobox

jQuery EasyUI Form Plugin - Combobox


jQuery EasyUI Plugins jQuery EasyUI Plugins


Extends $.fn.combo.defaults. Override the default defaults via $.fn.combobox.defaults.

The combobox displays an editable text box and a drop-down list from which users can select one or more values. Users can type text at the top of the list or select one or more existing values from the list.

Depends on

Usage

Create a combobox from an From the Create a combobox from markup.





Create a combobox using JavaScript.







$('#cc').combobox({

    url:'combobox_data.json',

    valueField:'id',

    textField:'text'

});

Create two dependent comboboxes.







Example of the JSON data format:



[{

    "id":1,

    "text":"text1"

},{

    "id":2,

    "text":"text2"

},{

    "id":3,

    "text":"text3",

    "selected":true

},{

    "id":4,

    "text":"text4"

},{

    "id":5,

    "text":"text5"

}]

property

This property extends from the combo; the following are properties added for the combobox.

Name Type Description Default value
valueField string The name of the underlying data bound to the value of this ComboBox. value
textField string The name of the underlying data bound to the text of this ComboBox. text
groupField string Indicates the field to be grouped. Available since version 1.3.4. null
groupFormatter function(group) Returns the group text to display on grouped items. Available since version 1.3.4.
 代码实例:     

$('#cc').combobox({     groupFormatter: function(group){         return '' + group + ''; } });| onSelect | event| onSelect | event | mode | string | Defines how to load the list data when the text changes. Set to 'remote' if the combo box (combobox) loads from the server. When set to 'remote' mode, the value entered by the user is sent to the server as an http request parameter named 'q' to fetch new data. | local| onSelect | event | url | string | The URL to load the list data from a remote source. | null| onSelect | event | method | string | The http method used to retrieve the data. | post| onSelect | event | data | array | The list data to be loaded.
Code example:



| null| onSelect | event | filter | function | Defines how to filter the local data when 'mode' is set to 'local'. This function has two parameters:
q: The text entered by the user.
row: The row data in the list.
Returning true allows the row to be displayed.

 代码实例:     

$('#cc').combobox({ filter: function(q, row){ var opts = $(this).combobox('options'); return row[opts.textField].indexOf(q) == 0; } }); | undefined| onSelect | event | formatter | function | Defines how to render a row. This function has one parameter: row.
Code example:

$('#cc').combobox({

    formatter: function(row){

        var opts = $(this).combobox('options');

        return row[opts.textField];

    }

});

| onSelect | event| onSelect | event | loader | function(param,success,error) | Defines how to load data from a remote server. Returning false cancels the action. This function has the following parameters:
param: The parameter object to pass to the remote server.
success(data): The callback function that is called when data is retrieved successfully.
error(): The callback function that is called when data retrieval fails. | json loader| onSelect | event | loadFilter | function(data) | Returns the filtered data to be displayed. This property is available since version 1.3.3.| onSelect | event |

Events

This event extends from Combo (combo), below are the events added for the combo box (combobox).

Name Parameters Description
onBeforeLoad param Triggered before a request to load data, returning false cancels the load action.
 代码实例:     

// change the http request parameters before load data from server $('#cc').combobox({ onBeforeLoad: function(param){ param.id = 2; param.language = 'js'; } });| onSelect | event | onLoadSuccess | none | Triggered when remote data is loaded successfully.| onSelect | event | onLoadError | none | Triggered when remote data fails to load.| onSelect | event | onSelect | record | Triggered when the user selects a list item.| onSelect | event | onUnselect | record | Triggered when the user deselects a list item. |

Method

This method extends from Combo (combo), below are the methods added or overridden for the combo box (combobox).

Name Parameters Description
options none Return the options object.
getData none Return the loaded data.
loadData data Load the local list data.
reload url Request remote list data. Pass the 'url' parameter to override the original URL value.
 代码实例:     

$('#cc').combobox('reload'); // reload list data using old URL $('#cc').combobox('reload','get_data.php'); // reload list data using new URL| onSelect | event | setValues | values | Sets the array of values for the combobox.
Code example:

$('#cc').combobox('setValues', ['001','002']);

| onSelect | event | setValue | value | Set the value of the combo box (combobox).
Code example:
$('#cc').combobox('setValue', '001');

| onSelect | event | clear | none | Clear the value of the combo box (combobox).| onSelect | event | select | value | Select the specified option.| onSelect | event | unselect | value | Deselect the specified option. |


jQuery EasyUI Plugins jQuery EasyUI Plugins