i perform filter , count of resulted rows in js file
filter by
1) locationid and
2) startdate between introductoryperiodstart , introductoryperiodend.
the following statement giving synatx error. please give me right statement.
$scope.newemps = $filter('filter')($scope.summary.corpemployees, { locationid: $scope.selecteditem.label } | { startdate:$scope.model.introductoryperiodstart:$scope.model.introductoryperiodend}).length;
code :
dashboardmodule.controller('dashboardcontroller', ['$scope','$filter', 'dashboardmoduleservice', function ($scope,$filter, dashboardmoduleservice) { $scope.selecteditems = {}; $scope.newemps; $scope.qualfd; $scope.scred; $scope.submtd8850misindocs; $scope.docsrecvd8850; $scope.docssubmtd8850; $scope.approved; $scope.denied; $scope.needmoreinfo; $scope.selecteditem; var ein = '0000000'; dashboardmoduleservice.getdashboardsummary(ein).then(function (response) { // $scope.summary = json.stringify(response.data.summary); $scope.summary = response.data.summary; $scope.corporateid = response.data.summary.corporateid; $scope.dropboxitemselected = function (item) { $scope.selecteditem = item; } console.log($scope.summary); }); $('#txtdaterange').on('apply.daterangepicker', function (ev, picker) { $scope.isrefreshing = true; $scope.model.introductoryperiodend = $filter('date')(new date(picker.enddate), 'mm/dd/yyyy'); $scope.model.introductoryperiodstart = $filter('date')(new date(picker.startdate), 'mm/dd/yyyy'); $scope.model.typeavailability = picker.chosenlabel === "custom range" ? "custom" : picker.chosenlabel; $scope.$apply(); console.log($scope.model.introductoryperiodend); console.log($scope.model.introductoryperiodstart); $scope.filterbydate(); }); angular.element(document).ready(function () { var dateconfiguration = new date(); $('#txtdaterange').daterangepicker({ locale:{ format: 'mm/dd/yyyy' }, autoapply: true }); loadchartcallcenter(); loadcharthumanefits(); loadchartqualificationsource(362, 100, 88); }); $scope.greaterthan = function (prop, val) { return function (item) { return item[prop] > val; } }; $scope.lessthan = function (prop, val) { return function (item) { return item[prop] < val; } }; $scope.filterbydate = function () { console.log($scope.selecteditem); console.log($scope.selecteditem.label); console.log($scope.model.introductoryperiodstart); console.log($scope.summary.corpemployees); $scope.newemps = $scope.$eval("summary.corpemployees | filter:{locationid:selecteditem.label} | filter:greatherthan('startdate',model.introductoryperiodstart) | filter:lessthan('startdate',model.introductoryperiodend)").length; } }; }]);
you have few errors: 0- date (greather / less) filters not defined. 1- can't use in way.
so: 0- define greatherthan
$scope.greaterthan = function(prop, val){ return function(item){ return item[prop] > val; } };
1- define lessthan
$scope.lessthan = function(prop, val){ return function(item){ return item[prop] < val; } };
2- use $scope.$eval
$scope.size = $scope.$eval("elements | filter:{locationid:location} | filter:greatherthan('startdate',initdate) | filter:lessthan('startdate',enddate)").length;
i updated better approach. check this:
i combine lessthan
greatherthan
in one: inrangedate
. plus, if not date automatically cast date.
$scope.inrangedate = function (prop, init, end) { return function(item){ init = init instanceof date ? init : new date(init); end = end instanceof date ? end : new date(end); return item[prop] > init && item[prop] < end; } };
check plunkr: http://plnkr.co/edit/bxpdnaujv6i0uujb8irp?p=preview (i apply on $scope.size
) 0. first approach in version 4 of plunkr 1. inrangedate approach in version 5 of same plunkr