Wednesday 8 June 2016

jquery filter function for table

jquery filter function for table

  <script>

            $(":checkbox").change(function ()
            {
                busFilterJqFun();
            });
            $("input[name='radioacnonac']").change(function () {
               
                busFilterJqFun();
              
            });
            $('input[name=radiosleeper]').change(function () {
              
                busFilterJqFun();
              
            });
            function busFilterJqFun()
            {
               
                $("#grvBusDetails tr").hide();
                $('#divfilteroops').empty();
                var arrbusname = [];
             
                var rows = $("#grvBusDetails tr");
             
                $("input[name='TravelName_chkbox']").each(function ()
                {
                    if ($(this).is(":checked"))
                    {
                        arrbusname.push('.' + $(this).val());
                    }
                });
                var arrbdname = [];
                $("input[name='boardinglist_chkbox']").each(function () {

                    if ($(this).is(":checked")) {
                        arrbdname.push('.' + $(this).val());
                    }
                });
                var arrdpname = [];
                $("input[name='droppingdatalist_chkbox']").each(function () {

                    if ($(this).is(":checked")) {
                        arrdpname.push('.' + $(this).val());
                    }
                });//droppingdatalist_chkbox
               
                var AcOrNonAc = $("input[name='radioacnonac']:checked").val();
                var sleeperOrseater = $("input[name='radiosleeper']:checked").val();
            
              
               
                if (arrbusname == "" && arrbdname == "" && AcOrNonAc == "" && arrdpname=="")
                {
                    rows.show();
                }
                else
                {
                    // otherwise, hide everything...
                    $("#grvBusDetails tr").hide();

                    // then show only the matching items
                    rows = $("#grvBusDetails tr").filter(arrbusname.length ? arrbusname.join(',') : '*');
                    //rows = $("#grvBusDetails tr").filter(arrbdname.length ? arrbdname.join(',') : '*');
                    if (arrbdname != "")
                    {
                              
                                rows = $(rows).filter(arrbdname.length ? arrbdname.join(',') : '*');
                             
                    }
                    if (arrdpname != "")
                    {
                       
                        rows = $(rows).filter(arrdpname.length ? arrdpname.join(',') : '*');
                      
                    }

                    if (AcOrNonAc)
                    {
                        AcOrNonAc = '.' + AcOrNonAc;
                      
                       
                        rows = $(rows).filter(AcOrNonAc != ".1" ? AcOrNonAc : '*');
                      
                    }
                    if (sleeperOrseater)
                    {
                        sleeperOrseater = '.' + sleeperOrseater;
                       
                        rows = $(rows).filter(sleeperOrseater != ".1" ? sleeperOrseater : '*');
                      
                    }
                    if (rows.size() > 0)
                    {
                        rows.show();
                    }
                    else
                    {
                        $('#divfilteroops').empty();
                        $('#divfilteroops').append('OOps No Bus found!!!!');
                    }
                }
            }

   </script>

No comments:

Post a Comment