EasyUI Forum
May 23, 2018, 05:36:01 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] Datagrid filter - Combobox loader  (Read 137 times)
jega
Jr. Member
**
Posts: 70


View Profile
« on: May 12, 2018, 12:26:40 PM »

Hi.

Want to load remote data to combobox by loader, but in combobox filter

It's easyu in a normal combobox like this

             <input id="searchWord" name="searchWord" class="easyui-combobox" style="width:300px" data-options="
                         loader: myloader,
                         mode: 'remote',
                         valueField: 'name',
                         textField: 'name',
                         hasDownArrow: false,
                         iconCls:'icon-search">

But now i want to do it in a filter combobox

Have this:

      dg.datagrid('enableFilter',[
         {field:'profileImage',type:'label'},
         {
            options:{
               valueField:id,
               textField:name,
               onChange:function(newVal,oldVal){
                  //CALL MYLOADER
               }
            }
         
         }
      ]);

But can't see how.

Regards

Jesper
« Last Edit: May 14, 2018, 02:16:33 AM by jega » Logged
jarry
Administrator
Hero Member
*****
Posts: 1374


View Profile Email
« Reply #1 on: May 13, 2018, 07:45:55 AM »

If your 'profileImage' field is the combobox filter, please try this:
Code:
{
field:'profileImage',
type:'combobox',
options:{
valueField: 'id',
textField: 'name',
loader: myloader,
mode: 'remote',
onChange:function(newVal, oldVal){
//...
}
}
}
Logged
jega
Jr. Member
**
Posts: 70


View Profile
« Reply #2 on: May 13, 2018, 12:42:18 PM »

Hi jarry.

Thanks for reply.

Before the post, i tried the same that you show in the sample, but i forgot the mode:'remote'. Added it, and the combobox now show matched keywords.
 
The datagrid have several columns, some that have a filter, and some without filter. The one i try with, is the column personName.

Sample: profileImage and mailaddress with no filter. On column personName i want a combobox (showed fine), but with loader.

      dg.datagrid('enableFilter',[
         {field:'profileImage',type:'label'},
         {field:'mailAddresse',type:'label'},
         {
            field:'personName',
            type:'combobox',
            valueField: 'name',
            textField: 'name',
            loader: myloader,
            mode: 'remote'
         }
      ]);


    var myloader = function(param,success,error){
        var searchWord = param.q || '';
   if (searchWord.length <= 1){return false}
        $.ajax({
            url: 'getfromdb.asp',
            type:'get',
            cache:false,
            data: {
                value: searchWord,
                st: 'remotelist',
                field: 'personName'
            },
            success: function(data){
                var items = $.map(data, function(item,index){
                       return {
                        id: index,
                        name: item
                    };
                });
                success(items);
            }             
        });

       
    }

When typing "ab" in the personName combobox filter, myloader returns all match with "ab". Pressing enter key or click, on one of the match in combobox, should filter datagrid with that word.

But how ??

Logged
jarry
Administrator
Hero Member
*****
Posts: 1374


View Profile Email
« Reply #3 on: May 14, 2018, 12:01:50 AM »

The combobox filtering field should be defined as:
Code:
{
field:'personName',
type:'combobox',
options: {
valueField: 'name',
textField: 'name',
loader: myloader,
mode: 'remote'
}
}
Logged
jega
Jr. Member
**
Posts: 70


View Profile
« Reply #4 on: May 14, 2018, 12:32:26 AM »

That's a typing error from me

My code is like you describe it

         {
            field:'personName',
            type:'combobox',
            options:{
               valueField: 'name',
               textField: 'name',
               loader: myloader,
               mode: 'remote'
            }
         }

When i type in the personName filter combobox, the loader returns result based on typing. Everything ok so far.

Now, when i'm finished typing, it doesn't do the filter, like in normal text. Think it only can do it on select /click list item, but how ??

Another thing. When typing jesper in personName filter, and tab to next filter (userID), typing in userID and stop typing, it do the filter, but in filterRules there is only the userID filter rule, not the personName filter rule.



Logged
jarry
Administrator
Hero Member
*****
Posts: 1374


View Profile Email
« Reply #5 on: May 14, 2018, 01:37:59 AM »

You should call 'addFilterRule' method to add a new filter rule when finish typeing. Something likes this:
Code:
{
field:'personName',
type:'combobox',
options: {
valueField: 'name',
textField: 'name',
loader: myloader,
mode: 'remote',
onChange: function(newValue, oldValue){
dg.datagrid('addFilterRule', {
field: 'personName',
op: 'equal',
value: newValue
});
dg.datagrid('doFilter');
}
}
}
Logged
jega
Jr. Member
**
Posts: 70


View Profile
« Reply #6 on: May 14, 2018, 02:16:12 AM »

Thanks jarry

Now it works   Grin


Jesper

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!