Jquery easyui combobox fuzzy filter of sample code

  • 2020-03-30 00:39:16
  • OfStack

Fix jquery easyui combobox blur filtering


filter:function(q,row){ 
var opts=$(this).combobox("options"); 

//return row[opts.textField].indexOf(q)==0;// 

return row[opts.textField].indexOf(q)>-1;//Change the ab initio position match to an arbitrary match
},formatter:function(row){ 
var opts=$(this).combobox("options"); 
return row[opts.textField]; 
},loader:function(_7c9,_7ca,_7cb){ 
var opts=$(this).combobox("options"); 
if(!opts.url){ 
return false; 
} 

Modify the easyui combobox extension to select the first line by default

By default, the first line of easyui's combobox extension is selected. The code that has been reprinted for countless times is crazy on the Internet, but that is only for easyui1.2.6, tried to do it under 1.3.2, and wrote an extension method as follows:


$.extend($.fn.combobox.methods, { 
    selectedIndex: function (jq, index) { 
        if (!index) { 
            index = 0; 
        } 
        $(jq).combobox({ 
            onLoadSuccess: function () { 
                var opt = $(jq).combobox('options'); 
                var data = $(jq).combobox('getData'); 

                for (var i = 0; i < data.length; i++) { 
                    if (i == index) { 
                        $(jq).combobox('setValue', eval('data[index].' + opt.valueField)); 
                        break; 
                    } 
                } 
            } 
        }); 
    } 
});

The example of the calling method is as follows:

<script type="text/javascript"> 
var currenturl = "om_taking.aspx"; 
        $(function () { 
            $('#dept').combobox({ 
                url: currenturl + "?act=loadDept", 
                valueField: 'DEPARTMENT_ID', 
                textField: 'DEPARTMENT_NAME'
            }).combobox('selectedIndex', 0); 
        }); 
</script> 


Related articles: