last day (39 days later) » 

2:38 PM
0
A: how to filter dates with angular?

DMCISSOKHOHi glad you succeed with the total ^^ you could do a formatDate() function which return the selected month and year and use it so <select ng-model="supplierExpenses.selectedOption" ng-change="setTotals(supplierExpenses)" ng-options = "item.date for item in supplierExpenses | un...

 
hey!! thanks I will try now
it doesn't work:( the table is being shown without me picking a date.
 
could you add the formatedDate() function to see what could be wrong ?
 
yes where to add?
 
in your question
 
I added - there are no errors. the table I being shown before I pick some date
can we continue with chat?
 
2:38 PM
yes of course :)
 
hello again!
<fieldset>
<legend class ="text-right ">דו"ח הוצאות לספקים</legend>
</fieldset>

<select ng-model="supplierExpenses.selectedOption" ng-change="setTotals(supplierExpenses)"
ng-options = "item.date for item in supplierExpenses |
unique:'date'" >

<option value="">בחר תאריך</option>
</select>



<div class="table-responsive">
<table class="customer-list table table-striped" >
<thead>
<tr >

<th class="Column-Header">מספר ספק</th>
<th class="Column-Header">שם ספק</th>
<th class="Column-Header">כמות מוצרים שנקנו</th>
maybe it need to be declared like the unqiue problem we had?
 
hi, so if i undertood , you have a date in a select and when you choose this date you have to sort by month (same as your date month) your table ?
 
now it sorts by the exact date that I pick. I want to sort by mounth and year for example when I choose : 10/2016 - > it will give all the information in that mounth
 
do you need exact date in your select ?
 
no just mounth and year
month*
 
2:50 PM
first, in your select you can add a filter ng-options = "item.date for item in supplierExpenses | unique:'date' | date:'MM/yyyy' "
 
ok
still the same :(
 
you still have the exact date in the select ?
 
the date is inserted to database like this : 2016-08-13
yes still the excat date and the table is shown before I pick something
 
ok i see , you will have to first convert your date to datime in your js
 
ok
how/
?
 
3:05 PM
.then(function(response) {
var arr = JSON.parse(JSON.parse(response.data));
for(var i = 0; i< arr.length; i++){
arr.date = new Date(arr.date ).toISOString();
}
$scope.supplierExpenses = arr;

})
something like this
then the date filter should work
 
ok one second
I have this error
angular.min.js:117RangeError: Invalid time value
 
ok you can remove this code it should have worked without
 
:(
 
when you do a console.log($scope.supplierExpenses); in your js what is printed ?
 
i removed the code you said should i put it back before or try like this?
Array[6]0: Object1: Object2: Object3: Object4: Object5: Objectlength: 6__proto__: Array[0]

supplierExpensesCtrl.js:7
Array[6]
0
:
Object
$$hashKey
:
"object:13"
date
:
"2016-08-07"
description
:
"קניית 3 מצלמות אבטחה מדגם "מצלמה 1""
name
:
"אבי אלקטרוניקה בע"מ"
supplier_id
:
"1"
total_price
:
"1560"
__proto__
:
Object
1
:
Object
2
:
Object
3
:
Object
 
3:27 PM
yes it's okay, and if you try the date filter without the unique filter, what happen ?
 
one minute
the same
 
ok i see a typo error in my previous code
for(var i = 0; i< arr.length; i++){
arr.date = new Date(arr.date);
}
could you try that
?
 
of course:)
the same no errors
 
3:43 PM
and what is the result of console.log($scope.supplierExpenses) ?
 
Array[6]
0
:
Object
$$hashKey
:
"object:13"
date
:
"2016-08-07"
description
:
"קניית 3 מצלמות אבטחה מדגם "מצלמה 1""
name
:
"אבי אלקטרוניקה בע"מ"
supplier_id
:
"1"
total_price
:
"1560"
__proto__
:
Object
1
:
Object
2
:
Object
3
:
Object
4
:
Object
5
:
Object
date
:
Invalid Date
length
:
6
 
another try

for(var i = 0; i< arr.length; i++){
arr[i].date = new Date(arr.date);
console.log(arr[i].date;
}
 
Invalid Date
supplierExpensesCtrl.js:8 Invalid Date
supplierExpensesCtrl.js:8 Invalid Date
supplierExpensesCtrl.js:8 Invalid Date
supplierExpensesCtrl.js:8 Invalid Date
supplierExpensesCtrl.js:8 Invalid Date
supplierExpensesCtrl.js:12 Array[6]0: Object$$hashKey: "object:13"date: Invalid Datedescription: "קניית 3 מצלמות אבטחה מדגם "מצלמה 1""name: "אבי אלקטרוניקה בע"מ"supplier_id: "1"total_price: "1560"__proto__: Object1: Object2: Object3: Object4: Object5: Objectlength: 6selectedOption: Object__proto__: Array[0]
if i do this code: for(var i = 0; i< arr.length; i++){
new Date(arr.date);
console.log(arr[i].date);
}
2016-08-07
supplierExpensesCtrl.js:8 2016-08-15
2supplierExpensesCtrl.js:8 2016-08-13
2supplierExpensesCtrl.js:8 2016-07-07
supplierExpensesCtrl.js:12 Array[6]0: Object1: Object$$hashKey: "object:14"date: "2016-08-15"description: "ד"name: "אבי אלקטרוניקה בע"מ"supplier_id: "1"total_price: "777"__proto__: Object2: Object3: Object4: Object5: Objectlength: 6selectedOption: Object__proto__: Array[0]
 
4:06 PM
it's better , with this and the filter is not working ?
 
the table is being shown without me picking a date...and the dates to choose still like this: 2016-8-15
 
if i do this code: for(var i = 0; i< arr.length; i++){
new Date(arr.date);
console.log(arr[i].date);
}

should be


if i do this code: for(var i = 0; i< arr.length; i++){
arr[i].date = new Date(arr[i].date);
console.log(arr[i].date);
}
i forgot the index in the new ate
Date
 
supplierExpensesCtrl.js:8 Sun Aug 07 2016 03:00:00 GMT+0300 (Jerusalem Daylight Time)
supplierExpensesCtrl.js:8 Mon Aug 15 2016 03:00:00 GMT+0300 (Jerusalem Daylight Time)
supplierExpensesCtrl.js:8 Sat Aug 13 2016 03:00:00 GMT+0300 (Jerusalem Daylight Time)
supplierExpensesCtrl.js:8 Sat Aug 13 2016 03:00:00 GMT+0300 (Jerusalem Daylight Time)
supplierExpensesCtrl.js:8 Thu Jul 07 2016 03:00:00 GMT+0300 (Jerusalem Daylight Time)
supplierExpensesCtrl.js:8 Thu Jul 07 2016 03:00:00 GMT+0300 (Jerusalem Daylight Time)
this from the console
this date is also showed where i need to pick a date
but the table is still working without me picking a date
 
ok so we move on, you still have the date filter ?
 
4:22 PM
yes
i have to go now for a couple of hours when i return i will write you! what do you think the next thing i should do?
 
try to make the date filter work then
the ng-if
 

  last day (39 days later) »