EasyUI Forum
May 21, 2024, 07:26:11 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Combobox or combogrid with intelli sense  (Read 9282 times)
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« on: February 21, 2015, 10:36:47 AM »

Generally in any ComboBox or in any ComboGrid if I type 'A', all option values starting with 'A' appears in dropdown, similarly if press 'AB', option values starting with 'AB' appears in dropdown and so on.

Is there any way that after type 1 or more character, instead of displaying all option values starting with given keys, all values CONTAINING the typed keys will appear in the dropdown, not only the option values starting with.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 22, 2015, 02:32:25 AM »

You can override the $.fn.combobox.defaults.filter function to define the filtering rule.
Code:
$.extend($.fn.combobox.defaults, {
  filter: function(q, row){
    var opts = $(this).combobox('options');
    return row[opts.textField].toLowerCase().indexOf(q.toLowerCase()) >= 0;
  }
});
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #2 on: February 22, 2015, 04:53:42 AM »

Wow! It really works like a charm.  Cheesy
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #3 on: February 22, 2015, 04:58:32 AM »

By the way, If I want to implement the same for ComboGrid what I have to do ? Directly if use the same code for ComboGrid it does not work.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: February 22, 2015, 05:49:20 AM »

For the combogrid, you can also override the $.fn.combogrid.defaults.filter function.
Code:
$.extend($.fn.combogrid.defaults, {
filter: function(q, row){
var opts = $(this).combogrid('options');
return row[opts.textField].indexOf(q) >= 0;
}
})
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #5 on: February 22, 2015, 08:25:43 AM »

I have tried with same code.

See the code below :

Code:
		<select id="cg" name="cg" class="easyui-combogrid" style="width:250px; padding-right:10px;" 
data-options="panelWidth: 500,
idField: 'secode2', textField: 'section',
url: 'getSection.php',
columns: [[
{field:'secode2',title:'SeCode',width:60,align:'right'},
{field:'secode',width:0,hidden:true},
{field:'section2',width:0, hidden:true},
{field:'section',title:'Section',width:260},
{field:'deptname',title:'Department',width:200}
]],
required:true,

and here is the code for filtering :

Code:
$.extend($.fn.combogrid.defaults, {
  filter: function(q, row){
    var opts = $(this).combogrid('options');
    return row[opts.textField].toLowerCase().indexOf(q.toLowerCase()) >= 0;
  }
});

But it does not filter as in case of combobox works, it shows all the rows, only it highlights the first occurence of the keypressed string.
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #6 on: February 22, 2015, 10:07:13 AM »

Problem solved, tricks were in 2 places.
1. mode:'remote' in combogrid data-options section and
2. in backend php file a $q parameter is send for selection query, but GOD knows how this parameter q is sent from combogrid, but it works.

Code:
$q = isset($_POST['q']) ? strval($_POST['q']) : '';

if($user_cat=='A') {
$sql = "select * from section where section like '%$q%' ORDER BY section";
}
else {
$sql = "select * from access where tno2='$user_tno2' and section like '%$q%' ORDER BY section";
}
« Last Edit: February 22, 2015, 09:03:20 PM by thecyberzone » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!