0

I'm currently working on one of my first angularJS projects and I'm stuck. So what am I trying to do?

I'm trying to filter my ng-repeat with a selected date from an input type = date this is my view:

<div class="form-group col-md-3">
    <label for="date">Tender Date</label>
    <input type="date" id="date" ng- model="searchDate.TenderDate"class="form-control">
</div>

<div >
    <table class="table table-bordered">

        <thead>

            <th>Tender ID</th>
            <th>Business unit</th>
            <th>Therapy Unit</th>
            <th>Tender Date</th>

        </thead>
        <tbody ng-repeat="tender in tenders | filter:searchDate">
            <td>{{tender.TenderID}}</td>
            <td>{{tender.businessUnit}}</td>
            <td>{{tender.therapyUnit}}</td>

            <td>{{tender.TenderDate}}</td>
        </tbody>

    </table>


</div>

This is my json file:

{
"Tenders":[{
            "businessUnit": "GN_RE S-RETAIL",
            "therapyUnit" : "Hospital Product ",
            "TenderID" : "BE_13_N2.1_001",
            "TenderDate" : "2016-03-17"
            },

            {
                "businessUnit": "GN_RE S-RETAIL",
                "therapyUnit" : "Hospital Product ",
                "TenderID" : "BE_13_N2.1_01",
                "TenderDate" : "2016-03-18"
            }


            ]
}

I have nothing in my controller. I am able to link a searchfield to a to a particular field in my array but the problem is the date type isn't working. I hope you guys can help me!

Sander Van Keer
  • 800
  • 5
  • 11
  • 22

2 Answers2

2

try this.

var myapp = angular.module('app', []);
myapp.controller('Main', function ($scope) {
  $scope.tenders = {
"Tenders":[{
            "businessUnit": "GN_RE S-RETAIL",
            "therapyUnit" : "Hospital Product ",
            "TenderID" : "BE_13_N2.1_001",
            "TenderDate" : "2016-03-17"
            },

            {
                "businessUnit": "GN_RE S-RETAIL",
                "therapyUnit" : "Hospital Product ",
                "TenderID" : "BE_13_N2.1_01",
                "TenderDate" : "2016-03-18"
            }


            ]
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app = "app">
  <div ng-controller="Main">
    <div class="form-group col-md-3">
    <label for="date">Tender Date</label>
    <input type="date" id="date" ng-model="searchDate"class="form-control">
</div>

<div >
    <table class="table table-bordered">

        <thead>

            <th>Tender ID</th>
            <th>Business unit</th>
            <th>Therapy Unit</th>
            <th>Tender Date</th>

        </thead>
        <tbody ng-repeat="tender in tenders.Tenders | filter: {TenderDate: searchDate }">
            <td>{{tender.TenderID}}</td>
            <td>{{tender.businessUnit}}</td>
            <td>{{tender.therapyUnit}}</td>

            <td>{{tender.TenderDate}}</td>
        </tbody>

    </table>


</div>
   </div>
</div>
Hadi J
  • 16,989
  • 4
  • 36
  • 62
1

You must mention by which column your filter will work

filter:{TenderDate:searchDate}
Hassan Tariq
  • 730
  • 7
  • 15