0

I am asking the user to select a week range, for example

1/2/2017 - 1/8/2017 (Monday-Friday, Saturday & Sunday would be the format of the week)

If there exists the data in the database for that week range, say from Monday to Friday, then

I am able to bind the above, however, i need to show the other two dates, at the end.(i.e 5 rows of Monday - Friday in database, no saturday and sunday in databse).

Date    Column1
1/2      1
1/3      2
1/4      3
1/5      4
1/6      5
1/7      0
1/8      0

How do i bind always 7 rows for each week, if the data is there in database, i want to show that, if not, just display the dates that are not in database and 0 against that.

$scope.MyWeekData = [];

In html,

<tr ng-repeat="week in MyWeekData" >
  <td>
    <label>
       {{week.Date | date:"MM/dd/yyyy" }} 
    </label>
  </td>
  <td>
    <label>
     <input name="column1" type="number" ng-model="week.Column1">
    </label>
    </td>
eko
  • 39,722
  • 10
  • 72
  • 98
Sharpeye500
  • 8,775
  • 25
  • 95
  • 143
  • is your problem, that the DB returns just the dates 1/2 to 1/6? (regarding to your sample data) – scipper Sep 15 '17 at 07:57

2 Answers2

1

Regarding to the answer of @Matt Johnson in iterate-through-a-range-of-dates-in-nodejs you can do the same:

Install momentjs and assign your data as follows:

$scope.MyWeekData = [];
let dateA = '1/2/2017';
let dateB = '1/8/2017';
for (let m = moment(dateA); m.diff(dateB, 'days') <= 0; m.add(1, 'days')) {
  $scope.MyWeekData.push({
    Date: m.format('MM/DD/YYYY'),
    Column1: //your value from response or 0
  });
}

I hope this helps.

scipper
  • 2,944
  • 3
  • 22
  • 45
0

I need to store all the days from start to end while saving the data, so that i can avoid this. That would be the right approach.

Sharpeye500
  • 8,775
  • 25
  • 95
  • 143