How to split the date based on check-In and check-out date in angularjs? -


i have hotel system need split date( duration of stay), start date( check-in) , enddate(check-out) selected user in datepicker. this:

<div class="datebox">      <input type="text" show-button-bar='false' class="form-control biginput" datepicker-popup ng-model="lodging.checkin" is-open="checkin" datepicker-options="dateoptions" ng-required="true" close-text="close"/>      <span class="dateicon" style='right:5px;' ng-click="opencheckin($event)"></span>   </div>  <div class="datebox">      <input type="text" show-button-bar='false'          class="form-control biginput" datepicker-popup          ng-model="lodging.checkout" is-open="checkout" min-date='lodging.checkin'          datepicker-options="dateoptions" ng-required="true"          close-text="close" />      <span class="dateicon" style='right:5px;' ng-click="opencheckout($event)"></span>  </div>

users choose check-in , check-out days above 2 datepicker. need split out information each stays, such if choose check-in : 11/01/2015 check-out: 11/05/2015, need create table show each stay's expense date 11/01/2015 11/05/2015. following table:

date           amount 11/01/2015     109 11/02/2015     120 11/03/2015     101 11/04/2015     99 

how split out duration date (like first columnn of table)and put them in ng-repeat table?

first, prepare table ng-repeat

<table ng-init="loadstays()" ng-if="stays">   <thead>     <tr>       <th>date</th>       <th>amount</th>     </tr>   </thead>   <tbody>     <tr ng-repeat="stay in stays | between:lodging.checkin:lodging.checkout">       <td>{{ stay.date | date : 'mm-dd-yyyy' }}</td>       <td>{{ stay.amount }}</td>     </tr>   </tbody> </table> 

then, create filter display items between date , date (if understand question correctly)

// parse date in format: 'mm-dd-yyyy' // if have parse date item (maybe datetime ?) // use built-in date filter // date = $filter('date')(item.date, 'mm-dd-yyyy') parsedate = function(input) {     var parts = input.split('-');     return new date(parts[1]-1, parts[2], parts[0]); };  // create filter assuming app module. app.filter('between', function() {   return function(items, from, to) {       filtered = [];       var datefrom = parsedate(from);       var dateto = parsedate(to);       if (from == '' && == '')           return items;       filtered = items.filter(function(item) {         if (from !== '' && == '') {           return item.date >= datefrom;         } else if (from == '' && !== '') {             return item.date <= datefrom;         } else if (from !== '' && !== '') {             return item.date >= datefrom && item.date <= dateto         }       });        return filtered;   }; }); 

with code, stays dynamically filtered , user see items date attribute between lodging.checkin , logding.checkout dates taken datepicker ng-models.

and in case of don't know how retrieve stays server, use :

// retrieve stays yourdomain/stays $scope.loadstays = function() {     $http.get('stays').then(function(response) {         $scope.stays = response.data;     }, function(response) {         console.log(response);     }); }; 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -