angularjs - Datetime range custom filter not working -


i trying filter list time frame. using angularjs, bootstrap datetimepicker , moment.js. happens not able list data. without custom filter able show list , simple text filter search. have added code related custom filter.

code related filter in controller

 app.controller('reportcontroller', ['$scope', 'report','$filter', function($scope, report,  $filter){          var self = this;           $filter('myfilter')(datefrom ,dateto);           app.filter('myfilter', function() {          return function(items, from, to) {          var result = [];                    (var i=0; i<items.length; i++){              var test = new date(items[i].datetime.$date);              var month = test.getmonth()+1;              var date = test.getdate();              var year = test.getfullyear();              var hour = test.gethours();              var minute = test.getminutes();              var second = test.getseconds();              var newdate = year+"-"+month+"-"+date+""+hour+"-"+minute+"-"+second;                        if (newdate > && newdate < to)  {                      result.push(items[i]);                      }                }                          return result;            };            });         }]); 

in html

<div ng-show="sradioption == 'showsearch2'" class='input-group date' id='datetimepicker6'>        <input type='text' ng-model="datefrom" class="form-control" />        <span class="input-group-addon">        <span class="glyphicon glyphicon-calendar"></span>        </span> </div> <div ng-show="sradioption == 'showsearch2'" class='input-group date' id='datetimepicker7'>     <input type='text' ng-model="dateto" class="form-control" />     <span class="input-group-addon">     <span class="glyphicon glyphicon-calendar"></span>     </span> </div>   <table class="table table-hover">  <thead>   <tr>     <th>c_number</th>     <th>datetime</th>     <th>reading</th>   </tr>  </thead>  <tbody>  <tr ng-repeat="r in ctrl.reports | filter:search | myfilter:datefrom:dateto">     <td>{{r.c_number}}</td>     <td>{{r.datetime}}</td>     <td>{{r.reading}}</td>   </tr>  </tbody> </table> 

you need take out filter out of controller,

app.filter('myfilter', function() {     return function(items, from, to) {         var result = [];         (var = 0; < items.length; i++) {             var test = new date(items[i].datetime.$date);             var month = test.getmonth() + 1;             var date = test.getdate();             var year = test.getfullyear();             var hour = test.gethours();             var minute = test.getminutes();             var second = test.getseconds();             var newdate = year + "-" + month + "-" + date + "" + hour + "-" + minute + "-" + second;             if (newdate > && newdate < to) {                 result.push(items[i]);             }         }         return result;     }; }); 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -