1

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!!

I am trying to implement a filter as shown in the image

{
"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"
    ]
}

}

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Saravanan
  • 1,237
  • 2
  • 18
  • 25
  • 1
    Besides what you want, also share what you have tried so far... – loxxy Feb 21 '13 at 05:18
  • You're going to need to use push() and slice() - [JavaScript Array reference](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array) – Mark Rajcok Feb 21 '13 at 20:30

1 Answers1

0

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)
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265