2016-11-25 56 views
0

我是新角js。 我想实现日期自定义筛选器使用日期选择器。 我已经尝试过,但我没有任何想法解决。 以下是我的代码。日期搜索筛选器不是在角js中工作

<div class="col-sm-2 m-b-xs"> 
    <input type="text" name="from_date" class="form-control" placeholder="From" date-time view="date" auto-close="true" min-view="date" ng-model="from_date" format="MMM-DD-YYYY" readonly /> 
     </div> 
<tr class="gradeU" ng-repeat="x in invoice | filter:{created : from_date}">  
    <td style="text-align: center;">{{ x.created | datetime }}</td>  
</tr> 
JS SECTION 
function InvoiceControllers($scope, $stateParams, $http, $state) { 
    $scope.filterData = {}; 
    $scope.invoice_listing = function (data) { 
     var json = (function() { 
      var json = null; 
      $.ajax({ 
       'async': false, 
       'global': false, 
       'url': 'invoices/listing_invoice', 
       'data': data, 
       'dataType': "json", 
       'success': function (data) { 
        // alert(data); 
        json = data; 
       } 
      }); 
      return json; 
     })(); 
     //$scope.formData = {value : json}; 
     $scope.invoice = json; 
    }; 
    var data = {}; 
    $scope.invoice_listing(data); 

    $scope.filter_invoice = function() { 
     var data = $scope.filterData; 
     $scope.invoice_listing(data); 
    }; 


} 

function dateTime($filter) { 
    return function (input) { 
     if (input == null) { 
      return ""; 
     } 

     var _date = $filter('date')(new Date(input), 'MMM-dd-yyyy'); 
     return _date.toUpperCase(); 

    }; 
} 

angular 
     .module('inspinia') 

     .controller('InvoiceControllers', InvoiceControllers) 

     .filter('datetime', dateTime); 

在这里,我试图从日期部分搜索的一部分。 enter image description here

任何建议。谢谢

+0

请使用“return _date;”而不是“return _date.toUpperCase();”在dateTime函数中。 –

回答

0

你遇到这个问题,因为在你的输入字段from_date设定模式值作为一个日期字符串。您需要使用表格列中使用的相同格式格式化日期。

var from_date = $filter('date')($scope.from_date, 'MMM-dd-yyyy'); 
$scope.invoice.filter({ created: from_date });