I am trying to implement a filter as shown in the image. I am using Angular JS framework, JQuery.
The requirement is , I have check box filter like Application Name , Status etc. On selecting an application or status I need to create a JSON dynamically like below . The value in "filterValues" should be automatically added or removed based on the check box values.
Based on the json value I will query the database and fetch the results and display.
I am constructing check box like below:
<div class="row-fluid">
<div ng-repeat="status in keywords.kw_Status">
<label class="checkbox">
<input type="checkbox" value="{{status}}" ng-model="isChecked" ng-change="change('Status','txt_Status',status,isChecked)">{{status}}
</label>
</div>
The coressponding controller code is as below
$scope.change=function(filterCategory, filterField, filterValue, filterAdd){
$scope.filters[filterCategory]={"filterField":filterField,"filterValues":[filterValue]};
console.log($scope.filters);
}
Any help is much appreciated!!

{
"Region": {
"filterField": "kw_Region",
"filterValues": [
"aa",
"bb"
]
},
"ApplicationName": {
"filterField": "kw_ApplicationName",
"filterValues": [
"aa",
"bb"
]
},
"IssueType": {
"filterField": "kw_IssueType",
"filterValues": [
"aa",
"bb"
]
},
"Outage": {
"filterField": "kw_Outage",
"filterValues": [
"aa",
"bb"
]
},
"Priority": {
"filterField": "kw_Priority",
"filterValues": [
"aa",
"bb"
]
}
}
The value in "filterValues" should be automatically added or removed based on the check box values.
Use JSON.stringify and a replacer callback to achieve this:
function replacer(match, offset, fullstring)
{
return replacer.str;
}
replacer.str = "\u0022filterValues\u0022:[\u0022hi\u0022,\u0022bye\u0022]"; /* Use DOM node value */
var foo = JSON.stringify({
"Region": {
"filterField": "kw_Region",
"filterValues": [
"aa",
"bb"
]
},
"ApplicationName": {
"filterField": "kw_ApplicationName",
"filterValues": [
"aa",
"bb"
]
},
"IssueType": {
"filterField": "kw_IssueType",
"filterValues": [
"aa",
"bb"
]
},
"Outage": {
"filterField": "kw_Outage",
"filterValues": [
"aa",
"bb"
]
},
"Priority": {
"filterField": "kw_Priority",
"filterValues": [
"aa",
"bb"
]
}
}).replace(/"filterValues[^\]]+./g, replacer)