Hi, let's see if you can help me, I'm very green with Angular Material
I have a table with N records and I am trying to filter by a range of dates. I have a select with the options (1 day, 5 days, 1 week, 15 days), which are loaded with a variable
JS
vm.rangos=[
{id:"1",name:'1 día',value:'1'},
{id:"2",name:'5 días',value:'5'},
{id:"3",name:'1 Semana',value:'7'},
{id:"4",name:'15 días',value:'15'}
];
HTML
<div layout="row" flex="90" layout-align="start center">
<label flex="25">Rango</label>
<select flex="60" ng-model="vm.rangoSelected" placeholder="" ng-options="ran.name for ran in vm.rangos" class="selectPersonalizado ">
</select>
</div>
and honestly I don't know how to do the function to perform the filter to show the results within the selected range
In this function I collect the value of the selected
function sendFilter(){
var filterSend = "";
switch(vm.filterSelected){
case 'rango':
filterSend = vm.rangoSelected.value;
break;
default:
alert('no hecho');
break;
}
vm.showLastMovements(filterSend);
}
In which with the alert, I get the value of the select well.
If you can help me or at least give me a clue to create said function and then make the call from the case so that the records of said selection are shown, I would appreciate it.
Thank you very much
I don't really understand the purpose of your switch, but I imagine it is to know if a filter has been selected and applied or not. For that, a simple if would suffice. I'll explain how I have a similar filter mounted.
In the select, I have the first option as 'No filter' with the value NO, and then I put the rest of the options. In the controller I initialize vm.rangeSelected= 'NO':
Then I pass the selected value to the filter function. Your filter function should do something like this:
To work with dates I recommend moment.js with which you can easily add dates:
moment().add(7, 'days');
or check if a date is within the range:fecha.isBetween(inicio, fin);