EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: alphasil on May 13, 2015, 10:06:36 AM



Title: filter problem
Post by: alphasil 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


Title: Re: filter problem
Post by: jarry on May 13, 2015, 03:03:58 PM
Please describe your question in more detail.


Title: Re: filter problem
Post by: alphasil 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?




Title: Re: filter problem
Post by: jarry 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');
    }
}


Title: Re: filter problem
Post by: alphasil 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>


Title: Re: filter problem
Post by: jarry 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:''
}]
});


Title: Re: filter problem
Post by: alphasil 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