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

jQuery EasyUI Form Plugin - Combogrid

jQuery EasyUI Form Plugin - Combogrid


jQuery EasyUI Plugins jQuery EasyUI Plugins


Extends $.fn.combo.defaults and $.fn.datagrid.defaults. Override the default defaults via $.fn.combogrid.defaults.

The combogrid combines an editable text box with a drop-down datagrid panel, allowing users to quickly find and select from the panel. The combogrid provides keyboard navigation support for selecting an item.

Depends on

Usage

Creating a Combogrid

1. Create a combogrid from markup.





2. Create from an existing element using JavaScript.







    $('#cc').combogrid({

    panelWidth:450,

    value:'006',

    idField:'code',

    textField:'name',

    url:'datagrid_data.json',

    columns:[[

    {field:'code',title:'Code',width:60},

    {field:'name',title:'Name',width:100},

    {field:'addr',title:'Address',width:120},

    {field:'col4',title:'Col41',width:100}

    ]]

    });

Autocomplete Feature

Let's add autocomplete functionality to the combogrid. The drop-down datagrid will display possible results based on user input.



$('#cc').combogrid({

    delay: 500,

    mode: 'remote',

    url: 'get_data.php',

    idField: 'id',

    textField: 'name',

    columns: [[

        {field:'code',title:'Code',width:120,sortable:true},

        {field:'name',title:'Name',width:400,sortable:true}

    ]]

});

On the server side, the 'q' parameter must be retrieved first. Users can query the database and then return an SQL result in JSON format to the browser.

get_data.php:



$q = isset($_POST['q']) ? $_POST['q'] : ''; // the request parameter

// query database and return JSON result data

$rs = mysql_query("select * from item where name like '$q%'");

echo json_encode(...);

property

This property extends from the combo and datagrid; the following are properties added for the combogrid.

Name Type Description Default value
loadMsg string The message displayed when the datagrid loads remote data. null
idField string The field name of the id. null
textField string The field name of the text displayed in the text box. null
mode string Defines how to load datagrid data when the text changes. Set to 'remote' if the combogrid loads from a server. In 'remote' mode, the value entered by the user is sent to the server as an HTTP request parameter named 'q' to retrieve new data. local
filter function(q, row) Defines how to select local data when 'mode' is set to 'local'. Return true to select the row.
 代码实例:     

$('#cc').combogrid({     filter: function(q, row){         var opts = $(this).combogrid('options');         return row[opts.textField].indexOf(q) == 0;     } }); | 100 |

Events

This event extends from Combo (combo) and Data grid (datagrid).

Method

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

Name Parameters Description
options none Return the options object.
grid none Returns the datagrid object. The following example shows how to get the selected rows:

var g = $('#cc').combogrid('grid'); // get datagrid object var r = g.datagrid('getSelected'); // get the selected row alert(r.name);| onSelect | event | setValues | values | Set an array of component values.
Code example:

$('#cc').combogrid('setValues', ['001','007']);

| onSelect | event | setValue | value | Set the component value.
Code example:
$('#cc').combogrid('setValue', '002');

| onSelect | event | clear | none | Clear the component value. |


jQuery EasyUI Plugins jQuery EasyUI Plugins