EasyUI Forum
December 08, 2025, 02:26:15 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Poll
Question: Null and not null
null - 0 (0%)
not null - 0 (0%)
Total Voters: 0

Pages: [1]
  Print  
Author Topic: filter problem  (Read 14665 times)
alphasil
Guest
« on: May 13, 2015, 10:06:36 AM »

Hi

I have a datagrid with enabled filter
Code:
 <script type="text/javascript">
                        $(function(){
                            var dg = $('#dg').datagrid();

                            dg.datagrid('enableFilter', [{
                                field:'dia',
                                type:'text',
                            },{
                                field:'sala',
                                type:'text',
                            },{
                                field:'inicio',
                                type:'combobox',
                                options:{
                                    panelHeight:'auto',
                                    data:[{value:'',text:'Livre'},{value:'P',text:'Ocupado'}],
                                    onChange:function(value){
                                        if (value == ''){
                                             dg.datagrid('addFilterRule', {
                                                field: 'inicio',
                                                op: 'equal',
                                                value: value
                                            });
                                        } else {
                                            dg.datagrid('addFilterRule', {
                                                field: 'inicio',
                                                value: not null
                                            });
                                        }
                                        dg.datagrid('doFilter');
                                    }
                                }
                            }]);

                        });

and the fields
Code:
 <th field="dia"width="150" sortable="true">Dia</th>
 <th field="sala" width="150" sortable="true">Sala</th>
 <th field="inicio" width="150" sortable="true">Tempos Alocados</th>


How to get value from not null beacuse my db has null and not null values

regards
Logged
jarry
Administrator
Hero Member
*****
Posts: 2303


View Profile Email
« Reply #1 on: May 13, 2015, 03:03:58 PM »

Please describe your question in more detail.
Logged
alphasil
Guest
« Reply #2 on: May 14, 2015, 06:33:37 AM »

Hi

I want to use the filter like in this filed

Code:
<th field="inicio" width="150" sortable="true">Tempos Alocados</th>
And the combobox filter has two option "Livre" (free) and "Ocupado" (busy)
"Livre" i have all the null values of my database

"Ocupado" i have all the non null values of my database


Is that possible?


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


View Profile Email
« Reply #3 on: May 14, 2015, 08:35:58 AM »

Please extend a 'notnull' filter operator and then apply it to the filtering action.
Code:
<script>
$.extend($.fn.datagrid.defaults.operators, {
notnull: {
text: 'NotNull',
isMatch: function(source, value){
return String(source) != '';
}
}
})
</script>

Code:
field:'inicio',
type:'combobox',
options:{
    panelHeight:'auto',
    data:[{value:'',text:'Livre'},{value:'P',text:'Ocupado'}],
    onChange:function(value){
        if (value == ''){
             dg.datagrid('addFilterRule', {
                field: 'inicio',
                op: 'equal',
                value: value
            });
        } else {
            dg.datagrid('addFilterRule', {
                field: 'inicio',
                op: 'notnull',
                value: value
            });
        }
        dg.datagrid('doFilter');
    }
}
Logged
alphasil
Guest
« Reply #4 on: May 14, 2015, 02:44:32 PM »

Hi

Thank you

I put the code like you told

It works but i have to hit refresh to get my result, is that right?

The first and second filter doesn't work...why?

Code:
 dg.datagrid('enableFilter', [{
                                field:'dia',
                                type:'text',
                            },{
                                field:'sala',
                                type:'text',
                            }

Code:
<th field="dia"width="150" sortable="true">Dia</th>
<th field="sala" width="150" sortable="true">Sala</th>
« Last Edit: May 14, 2015, 02:56:48 PM by alphasil » Logged
jarry
Administrator
Hero Member
*****
Posts: 2303


View Profile Email
« Reply #5 on: May 14, 2015, 06:27:58 PM »

When creating the datagrid, you can set the 'filterRules' property to initialize the filtering action. Please refer to the following code.
Code:
$('#dg').datagrid({
filterRules:[{
field:'inicio',
op:'equal',
value:''
}]
});
Logged
alphasil
Guest
« Reply #6 on: May 20, 2015, 05:44:07 AM »

Hi

Sorry for the delay but i was out.
I don't understand what do you mean, put this code where?

Regards
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!