Thursday, 23 June 2011

Filter the table using pop up div

function imagefilerClick()
 {
       $('#tableresult th div img.filter').click(function (e) {  
        $("#filterDivOuter").show();
        cellNo = $("#tableresult th").index($(this).parents('th'));
       
        var filterlistItems = "";
        var vals = new Array();
        var i=0;
        var options='';
       
        $('#tableresult td:nth-child(' + (cellNo + 1) + ')').each(function(){
           var t=$(this).html();
           if(t==" ")
            t="" 
                                           
           if($.inArray(t, vals) < 0)
           {
               vals[i]=t;
               i++;
           }
        });
       
        for(var j=0;j<i;j++)
        {    
            var chkbxName = vals[j];//.replace(/\s/g,"");
                       
            filterlistItems = filterlistItems + "<input class='allCheckConatiner' type='checkbox' value= '" + cellNo + "'  checked='checked'  name = '" + chkbxName + "' /> <label>" + vals[j] + "</label><br />";
        
        }                                            
       
        $('#filterDivInner').html(filterlistItems);
         
        filterlistItems ="";
       
       
            var x = e.pageX;         
            x = x- 100;
            var y = e.pageY;
            y = y - 90;
           
            if(x > $(window).width()-190)
                x = x -  39;
            if(x<0)
                x = 5;
               
               
           
           
           
            jQuery("#filterDivOuter").css({
                "position": "absolute", "display": "block",
                "top": y,
                "left": x
            });
         
             
          $("#filterDivInner input[type=checkbox]").each(function() {
         
   
             var crow = $(this).attr("name");            

                var condition="";
                if(crow!=null)
                {
                if (crow  =='' || crow  == ' ' )
                    condition = $('#tableresult tr:last:contains("' + crow + '")').css('display') == "none" ;                    
                else
                    condition = $('#tableresult tr:contains("'+ crow +'")').css('display') == "none" ;
               
                }
               
                 
                 
                 
                   if(condition)              
                   {
                        $(this).attr("checked", false);
                   }
                   else
                   {
                       
                        $(this).attr("checked", true);                  
                   }
            
        
          }); // end $("#filterDivInner input[type=checkbox]").each(function()
                 
    

    }); // $('#tableresult th div img.filter').click on click open popup

No comments:

Post a Comment