EasyUI Forum
September 14, 2025, 02:54:20 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: filter row datagrid with checkbox with three states  (Read 11514 times)
Opan Mustopah
Full Member
***
Posts: 164


Indonesia


View Profile Email
« on: February 01, 2015, 07:40:10 PM »

hello again.

how to make datagrid filter row to achieve feature filtering row with chekcbox with 3 states?
like default: all, on: true, off: false?

Code:
checkbox:{
      init: function(container, options){
        var span = $('<span class="tree-checkbox tree-checkbox0" style="position:relative;top:2px"></span>').appendTo(container);
        span.attr('onval', options.on).attr('offval', options.off);
        span.bind('click',function(){
          if ($(this).hasClass('tree-checkbox1')){
            $(this).val(options.off);
            $(this).removeClass('tree-checkbox1').addClass('tree-checkbox0');
          } else {
            $(this).val(options.on);
            $(this).removeClass('tree-checkbox0').addClass('tree-checkbox1');
          }
        });
        console.log(span);
        return span;
      },
      getValue: function(target){
        if ($(target).hasClass('tree-checkbox1')){
          return $(target).attr('onval');
        } else {
          return $(target).attr('offval');
        }
      },
      setValue: function(target, value){
        if ($(target).attr('onval') == value){
          $(target).removeClass('tree-checkbox0').addClass('tree-checkbox1');
        } else {
          $(target).removeClass('tree-checkbox1').addClass('tree-checkbox0');
        }
      },
      resize:function(target,width){

      }
    }

i already try to extend new filter with checkbox that i found on some post here, but this only two states, on: true and off: false. but actually this isn't work yet, because when i try to click that checkbox nothing happened to my datagrid.

how to do that?

many thanks for the answer
Logged

-- Bajak Otak --
*** Sorry for my bad english :3 ***
--JeasyUI version 1.4--
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 02, 2015, 12:51:53 AM »

Please try this extended filter:
Code:
$.extend($.fn.datagrid.defaults.filters,{
checkbox:{
init: function(container, options){
var span = $('<span class="tree-checkbox tree-checkbox0"></span>').appendTo(container);
span.bind('click',function(){
if ($(this).hasClass('tree-checkbox0')){
$(this).removeClass('tree-checkbox0').addClass('tree-checkbox1');
this.v = 'checked';
} else if ($(this).hasClass('tree-checkbox1')){
$(this).removeClass('tree-checkbox1').addClass('tree-checkbox2');
this.v = 'indeterminate';
} else {
$(this).removeClass('tree-checkbox2').addClass('tree-checkbox0');
this.v = 'unchecked';
}
if (options.onChange){
options.onChange.call(this, this.v);
}
})
return span;
},
getValue: function(target){
return target.v;
},
setValue: function(target, value){
$(target).removeClass('tree-checkbox0 tree-checkbox1 tree-checkbox2');
if (value == 'checked'){
$(target).addClass('tree-checkbox1');
} else if (value == 'indeterminate'){
$(target).addClass('tree-checkbox2');
} else {
$(target).addClass('tree-checkbox0');
}
},
resize: function(target, width){

}
}
});
Logged
Opan Mustopah
Full Member
***
Posts: 164


Indonesia


View Profile Email
« Reply #2 on: February 02, 2015, 12:53:17 AM »

thanks stworthy for your replay, i'll try it ASAP.
Logged

-- Bajak Otak --
*** Sorry for my bad english :3 ***
--JeasyUI version 1.4--
Opan Mustopah
Full Member
***
Posts: 164


Indonesia


View Profile Email
« Reply #3 on: February 26, 2015, 04:44:33 AM »

hello stworthy, i already try your extended filter,

here is my code:

Code:

$list_data.datagrid('enableFilter', [
   
      {field: 'updated_at',type: 'dateRange',op: 'betweenDate'},       
      {field: 'pi_date',type: 'dateRange',op: 'betweenDate'},       
      {field: 'post_date',type: 'dateRange',op: 'betweenDate'},       
      {field: 'due_date',type: 'dateRange',op: 'betweenDate'},       
      {field: 'currency_rate',type: 'numberRange',op: 'betweenNumber'},       
      {field: 'amount_tax',type: 'numberRange',op: 'betweenNumber'},       
      {field: 'amount_pi',type: 'numberRange',op: 'betweenNumber'},       
      {field: 'is_pi_or_ret',type: 'checkbox',options: optFilterCheckbox($list_data, 'is_pi_or_ret', 'equal')},       
      {field: 'action', type: 'label'}
    ]);

function optFilterCheckbox(){
    var dg = arguments[0];
    var field = arguments[1];
    var op = arguments[2]

    var opts = {
      onChange:function(target, value){

        console.log(value);
        console.log(target);
        console.log(dg);
        //doFilter(dg);

        /*
        if (value == 'checked'){ 
          addFilterRule(field, true, op, dg);
        }else if (value == 'indeterminate'){
          addFilterRule(field, false, op, dg);
        }else{
          removeFilterRule(field, dg);
        }
        */
        // doFilter(dg);
      }
    }

    return opts;
  } 

i make the filter options dynamic, but i can filter data correctly, the checkbox state won't change when i click it. but when i comment filter rule, i can change checkbox state, but i can't getting checkbox filter value. i can't get value from getValue function on extend filter code.

thanks in advancce
Logged

-- Bajak Otak --
*** Sorry for my bad english :3 ***
--JeasyUI version 1.4--
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!