Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to filter the table by date. I want table to be filtered when I changed date.

I have used jquery date picker for calender.

Right now I have added a button and which on click (ng-click) call angular js function to filter table. but I want this function to be called on ng-change event. Some thing like this.

Please check my code below and let me know what do I need to change to make it work.

Thank you.

What I have tried:

My code:

code in controller:

$('#dtRms2').datepicker({
        changeMonth: true,
        changeYear: true,
        showAnim: 'slideDown',
        duration: 'fast',
        dateFormat: 'mm/dd/yy',
        onSelect: function (date) {
            $scope.Login_Val = date;
            $scope.$apply();
        }
    });
	
	
	
 $scope.OnLoginChange = function (LoginChangeFilter, inputVal) {

                $scope.Tables = $scope.allTables;
                debugger;
                console.log(LoginChangeFilter);
                console.log(inputVal);
                //let 
                var newArray = [];
                    <pre>switch (LoginChangeFilter) {
                        case '=':

newArray = $scope.Tables.filter(function (r) {
var d1 = new Date(r.lgDt.toString());
var d2 = new Date(inputVal.toString());
debugger;
if (d1.getTime() === d2.getTime()) {
return r;
}
});
debugger;
break;
case '>=':


newArray = $scope.Tables.filter(function (r) {
var d1 = new Date(r.lgDt.toString());
var d2 = new Date(inputVal.toString());

if (d1.getTime() >= d2.getTime()) {
return r;
}
});
debugger;
break;
case '<=':
newArray = $scope.Tables.filter(function (r) {
var d1 = new Date(r.lgDt.toString());
var d2 = new Date(inputVal.toString());


if (d1.getTime() <= d2.getTime()) {
return r;
}
});

break;
default:
newArray = $scope.Tables
break;
}

$scope.Tables = newArray;
}


HTML:
<td>
                            <table>
                                <tr>
                                    <td>
                                        <select ng-model="LoginChangeFilter">
                                            <option ng-repeat="c in Comparers" value="{{c}}">{{c}}</option>
                                        </select>
                                    </td>
                                    </tr>
                                <tr>
                                    <td>
                                        <input type="text" id="dtRms2" ng-model="Login_Val" ng-change="OnRmsLoginChange(LoginChangeFilter,Login_Val)">{{RmsLogin_Val}}
                                    </td>
                                    <td>
                                        <%--<input type="hidden" id="start" ng-model="Login_Val" ng-change="OnLoginChange(LoginChangeFilter,Login_Val)"/>--%>
                                        <input type="button" value="Go" ng-click="OnRmsLoginChange(LoginChangeFilter,Login_Val)" />
                                    </td>
                                </tr>
                            </table>
                        </td>          
Posted
Updated 25-Jul-17 6:31am

1 solution

It worked . I had typo error in variable name.
$('#dtRms2').datepicker({
       changeMonth: true,
       changeYear: true,
       showAnim: 'slideDown',
       duration: 'fast',
       dateFormat: 'mm/dd/yy',
       onSelect: function (date) {
           $scope.Login_Val = date;

           var dtDate = $scope.LoginVal;
           var cmp = $scope.LoginChangeFilter;
           //$scope.OnLoginChange(cmp, dtDate);
$scope.OnLoginChange(cmp, dtDate);

           $scope.$apply();
                  }
   });
 
Share this answer
 
v3
Comments
Graeme_Grant 16-Sep-17 8:09am    
Please don't answer your own question with a solution and then accept it as a valid solution. This is see as REP farming and can get you banned if continued. Update your question instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900