In Angularjs app, i am using ng-options to display the user and valid from date.
Here i am having a checkbox which will be checked default means only valid rates needs to be displayed..
Here valid rates mean the rates which have recent date for each user..
If showvalidrates = false expected result as follows,
ASSIST.. / Assistance [valid from 2017-05-01]
ASSIST.. / Assistance [valid from 2018-01-01]
ASSIST.. / Assistance [valid from 2019-01-01]
PROF.. / Professional [valid from 2017-05-01]
PROF.. / Professional [valid from 2018-01-01]
PROF.. / Professional [valid from 2019-01-01]
SEN.. / Senior [valid from 2018-01-01]
SEN.. / Senior [valid from 2019-01-01]
SEN.. / Senior [valid from 2017-05-01]
If showvalidrates = true expected result as follows,
ASSIST.. / Assistance [valid from 2019-01-01]
PROF.. / Professional [valid from 2019-01-01]
SEN.. / Senior [valid from 2019-01-01]
For this filter of latest data i have already implemented code so no problem for it,
You can look at the demo below which has all the code used in app.js.
Working Demo: http://plnkr.co/edit/gFCfMhaFzTq1xHv1P3T1?p=preview
I am in need of help in the part how to send this filtered list to the ng-options if showvalidrates = true.. Else if it is false then it will display all the records from item.jobcategories ..
Reference link: https://codepen.io/anon/pen/GbWKLp
This is just a reference link and i need to solution in the plunker. In codepen, it has valid as property and based on that filter happens, sameway i am in the need to send the filtered values from the result comes from
const getDate = date => +date.match(/[0-9]{4}-[0-9]{2}-[0-9]{2}/g)[0].split('-').join('')
data = $scope.rateschedule[0].jobcategories.sort(({jobCategoryWithFromDate:date1}, {jobCategoryWithFromDate:date2}) => getDate(date2) - getDate(date1))
const getRecent = (data, i=0) => getDate(data[i].jobCategoryWithFromDate) === getDate(data[i + 1].jobCategoryWithFromDate) ? [data[i], ...getRecent(data, i+1)] : [data[i]]
getRecent(data).forEach(obj => console.log(JSON.stringify(obj)))
(Here in codepen, filter happens based on valid property, likewise in plunker i have to send the filtered value to ng-options)
As i already have the filtering code to get latest data, kindly help me to send it to ng-options..
Any alternative solution to handle this with select box would also be more appreciable..
Struggling for long long time please help me with good solution..
Hope this snippet helps!