JqGrid - inline editing with autocomplete

I am sure that I have already seen this in the example, but I can not find it again :(

I have jqGrid with inline editing. It works great. One column has a select box with 200 items. They are already retrieved from the database query.

Since 200 entries are too many, I want to have an input field and a direct search. After clicking on it, the identifier should be saved.

Does anyone know an example?

Thanks a lot Antonia

+3
source share
2 answers

jQuery-ui autocomplete, jquery ui. combobox.js, , "combobox" .

// jquery and jquery UI already loaded...
<script src="combobox.js"></script>
<select class="combobox">
    <option value="foo">foo</option>
    <option value="bar">bar</option>
    <option value="baz">baz</option>
</select>

: http://jsfiddle.net/CJTd2/1/

+1

:

function element(value,options){
    return $('<input type="hidden" value="'+value+'" />');
}
function elementval(elem){
    return elem.val();
}
function fieldfunctions(id){
    $( "#"+id+"_name").autocomplete({
        source: "list.php",
        minLength: 2,
        select: function(event, ui) {
            $("#"+id+"_id_name").val(ui.item.id);
        }
    });
}

$("#table").jqGrid({
    url: 'data.php',
    datatype: "json",
    mtype: 'POST', 
    height: 400,
    colNames: ['Name','Id name'],
    colModel: [
        {name: 'id_name',width: 30,hidden:true,editable:true,edittype:'custom',editoptions:{custom_element:element,custom_value:elementval}},
        {name: 'name',index: 'name',editable:true,edittype:'text',width: 100}

    ],
    onSelectRow: function(id){
        $("#table").jqGrid('editRow',id, true,fieldfunctions);
        }
    });
+1

Source: https://habr.com/ru/post/1772071/


All Articles