Reputation: 454
Consider this as my json data. I want to filter the "gridValues" in the data using value "LAN". I have used Ext js filter method. It doesn't return the filter data.
var tableData = [
{
"TABLE_TITLE": "Details",
"tableColumns": {
"COLUMNNAME_0": "Interface",
"COLUMNNAME_1": "Conversation",
"COLUMNNAME_2": "Data Flow(KB)"
},
"gridValues": [
{
"COLUMVal_0": "LAN",
"COLUMVal_1": "192.168.9.113 to 61.16.173.233",
"COLUMVal_2": "1132.7"
},
{
"COLUMVal_0": "TATA",
"COLUMVal_1": "192.168.8.67 to 111.221.115.98",
"COLUMVal_2": "619.72"
},
{
"COLUMVal_0": "CITI",
"COLUMVal_1": "192.168.8.60 to 23.6.112.201",
"COLUMVal_2": "619.2"
}
]
}
];
I used the following code for filtering data:
var arry =[];
var fliterarry =[];
var i,u;
for (i=0;i<tableData.length;i++) {
arry.push(tableData[i].gridValues);
}
var arryFtr = arry.filter(function(e){
for (u=0;u<e.length;u++) {
if(e[u].COLUMVal_0 === 'TATA'){
tableData[u].gridValues.push(e[u]);
}
return e[u].COLUMVal_0 == 'TATA';
}
return fliterarry
});
Upvotes: 0
Views: 332
Reputation: 443
I guess you want to filter data with COLUMVal_0 equals "TATA" , right ?
Try following codes in your function :
var filterArray = [];
for ( tdKey in tableData ) {
for ( gvKey in tableData[tdKey].gridValues ) {
if ( tableData[tdKey].gridValues[gvKey].COLUMVal_0 == "TATA" ) {
filterArray.push(tableData[tdKey].gridValues[gvKey]);
}
}
}
return fliterarry;
Upvotes: 2