I trying to filter the data, wherein I have multiple filters. I have tried multiple techniques with map(), for but I am getting all the objects or none of them.
filtersSelected is the object where all my filters are placed.
status is data[i].status, amount is data[i].payment_detail.amount_charges.lc_amount
I was trying to filter the data depending upon user selection, filtersSelected is keys selected by the user in the front end. User can select the data in any order(Filter selected).
var filtersSelected = {
status: ['acknowledged', 'save_as_draft'],
amount: [100000009],
expiry: [],
};
var data = [{
"user_id": "admin",
"uuid": "3cade470-c0ba-11e9-9adc-795e8c9df56c",
"common_info": {
"lc_name": "",
"lc_id": "as3d24sfi",
"initiation_date": "",
"lc_type": "conventional"
},
"general_info": {
"applicant_detail": {
"bank_name": "FGBCONV",
"issuer_reference": "GHQ ARMED Forces Direct of Fin Aff",
"name": "G H Q"
},
"beneficiary_detail": {
"name": "Tafale Aero Systems"
},
"lc_detail": {
"expiry_date": "2019-08-31T00:00:00.000Z"
},
"valid": true,
"visited": true
},
"payment_detail": {
"amount_charges": {
"lc_amount": 100000009,
"currency": "Dirhams"
},
"valid": true,
"visited": true
},
"bank_other_party_detail": {
"credit_available": {
"type": "Any Bank",
"credit_available_by": ""
},
"valid": true,
"visited": true
},
"shipment_detail": {
"general_info": {
"shipment_from": "qwert",
"shipment_to": "qwerty"
},
"valid": true,
"visited": true
},
"narrative_detail": {
"valid": true,
"visited": true
},
"attached_documents": [],
"status": "acknowledged",
"status_updated_at": 1566231731134,
"updatedAt": "1566025738195",
"createdAt": "1566024172600",
"valid": false,
"visited": false
}, {
"user_id": "admin",
"uuid": "040887d0-bcf8-11e9-9ead-37268ca96a91",
"common_info": {
"lc_name": "Gunther Systems_32",
"lc_id": "1023LC2313",
"initiation_date": "16-05-2019",
"lc_type": "Conventional"
},
"general_info": {
"applicant_detail": {
"bank_name": "TC Gorsch_88",
"issuer_reference": "Emirate of Abu Dhabi Finance Dept",
"name": "GHQ"
},
"beneficiary_detail": {
"name": "Gunther Systems S.A."
},
"lc_detail": {
"expiry_date": "2019-05-09T00:00:00.000Z"
},
"valid": false,
"visited": false
},
"payment_detail": {
"amount_charges": {
"lc_amount": 800000,
"currency": "EUR"
},
"valid": false,
"visited": false
},
"bank_other_party_detail": {
"credit_available": {
"type": "UBDS Bank",
"credit_available_by": "By Def Payment"
},
"valid": false,
"visited": false
},
"shipment_detail": {
"general_info": {
"shipment_from": "Atlanta, USA",
"shipment_to": "Abu Dhabi, UAE"
},
"valid": false,
"visited": false
},
"narrative_detail": {
"valid": false,
"visited": false
},
"attached_documents": [{
"file_name": null,
"file_path": null
}],
"status": "returned_to_ghq_for_correction",
"status_updated_at": 1566231731134,
"updatedAt": "1565970913070",
"createdAt": "1565610901767",
"valid": false,
"visited": false
}, {
"user_id": "admin",
"uuid": "fefc48b0-bce5-11e9-a1f1-93c532b8cd7a",
"common_info": {
"lc_name": "South West Corp 007",
"lc_id": "1023LC2312",
"initiation_date": "21/12/2018",
"lc_type": "Conventional"
},
"general_info": {
"applicant_detail": {
"bank_name": "TC Gorsch",
"issuer_reference": "G H Q Directorate of FIN Affairs",
"name": "GHQ"
},
"beneficiary_detail": {
"name": "Tafale Aero Systems"
},
"lc_detail": {
"expiry_date": "2019-05-09T00:00:00.000Z"
},
"valid": false,
"visited": false
},
"payment_detail": {
"amount_charges": {
"lc_amount": 9000000,
"currency": "USD"
},
"valid": false,
"visited": false
},
"bank_other_party_detail": {
"credit_available": {
"type": "Any Bank",
"credit_available_by": "By Def Payment"
},
"valid": false,
"visited": false
},
"shipment_detail": {
"general_info": {
"shipment_from": "Atlanta, USA",
"shipment_to": "Abu Dhabi, UAE"
},
"valid": false,
"visited": false
},
"narrative_detail": {
"valid": false,
"visited": false
},
"attached_documents": [],
"status": "submitted_to_bank_for_authorization",
"status_updated_at": 1566231731134,
"updatedAt": "1565603162342",
"createdAt": "1565603162342",
"valid": false,
"visited": false
}, {
"user_id": "admin",
"uuid": "8686fe30-bce4-11e9-a1f1-93c532b8cd7a",
"common_info": {
"lc_name": "South Corp_89",
"lc_id": "1023LC2329",
"initiation_date": "11/05/2016",
"lc_type": "Conventional"
},
"general_info": {
"applicant_detail": {
"bank_name": "TC Gorsch_18",
"issuer_reference": "G H Q Directorate of FIN Affairs",
"name": "GHQ"
},
"beneficiary_detail": {
"name": "Marthsell Adv Tech Solutions"
},
"lc_detail": {
"expiry_date": "2019-05-09T00:00:00.000Z"
},
"valid": false,
"visited": false
},
"payment_detail": {
"amount_charges": {
"lc_amount": 4500000,
"currency": "USD"
},
"valid": false,
"visited": false
},
"bank_other_party_detail": {
"credit_available": {
"type": "Any Bank",
"credit_available_by": "By Def Payment"
},
"valid": false,
"visited": false
},
"shipment_detail": {
"general_info": {
"shipment_from": "Atlanta, USA",
"shipment_to": "Abu Dhabi, UAE"
},
"valid": false,
"visited": false
},
"narrative_detail": {
"valid": false,
"visited": false
},
"attached_documents": [],
"status": "approaching_expiry",
"status_updated_at": 1566231731134,
"updatedAt": "1565602530750",
"createdAt": "1565602530750",
"valid": false,
"visited": false
}, {
"user_id": "admin",
"uuid": "1d154790-bce4-11e9-a1f1-93c532b8cd7a",
"common_info": {
"lc_name": "North and South Corp_89",
"lc_id": "1023LC2310",
"initiation_date": "11/05/2016",
"lc_type": "Conventional"
},
"general_info": {
"applicant_detail": {
"bank_name": "TC Gorsch_18",
"issuer_reference": "G H Q Directorate of FIN Affairs",
"name": "GHQ"
},
"beneficiary_detail": {
"name": "Hewlett Harbin First Mach"
},
"lc_detail": {
"expiry_date": "2019-05-09T00:00:00.000Z"
},
"valid": false,
"visited": false
},
"payment_detail": {
"amount_charges": {
"lc_amount": 4500000,
"currency": "USD"
},
"valid": false,
"visited": false
},
"bank_other_party_detail": {
"credit_available": {
"type": "Any Bank",
"credit_available_by": "By Def Payment"
},
"valid": false,
"visited": false
},
"shipment_detail": {
"general_info": {
"shipment_from": "Atlanta, USA",
"shipment_to": "Abu Dhabi, UAE"
},
"valid": false,
"visited": false
},
"narrative_detail": {
"valid": false,
"visited": false
},
"attached_documents": [],
"status": "not_processed",
"status_updated_at": 1566231731134,
"updatedAt": "1565602353885",
"createdAt": "1565602353885",
"valid": false,
"visited": false
}, {
"user_id": "admin",
"uuid": "f5a59830-bcdf-11e9-9264-812f5d20a14a",
"common_info": {
"lc_name": "North and South Corp_89",
"lc_id": "1023LC2316",
"initiation_date": "11/05/2016",
"lc_type": "Conventional"
},
"general_info": {
"applicant_detail": {
"bank_name": "TC Gorsch_18",
"issuer_reference": "G H Q Directorate of FIN Affairs",
"name": "GHQ"
},
"beneficiary_detail": {
"name": "Hewlett Harbin First Mach"
},
"lc_detail": {
"expiry_date": "2019-08-20T00:00:00.000Z"
},
"valid": false,
"visited": false
},
"payment_detail": {
"amount_charges": {
"lc_amount": 4500000,
"currency": "USD"
},
"valid": false,
"visited": false
},
"bank_other_party_detail": {
"credit_available": {
"type": "Any Bank",
"credit_available_by": "By Def Payment"
},
"valid": false,
"visited": false
},
"shipment_detail": {
"general_info": {
"shipment_from": "Atlanta, USA",
"shipment_to": "Abu Dhabi, UAE"
},
"valid": false,
"visited": false
},
"narrative_detail": {
"valid": false,
"visited": false
},
"attached_documents": [],
"status": "not_processed",
"status_updated_at": 1566153000000,
"updatedAt": "1565600569724",
"createdAt": "1565600569724",
"valid": false,
"visited": false
}];
function updateData(data) {
// 'save_as_draft'
const updatedDataArr = data.filter(item => {
for (key in filtersSelected) {
if (item.status === filtersSelected[key]) {
return false;
}
// arr = filtersSelected[key].map( selectedFilter => {
// if(item.status === selectedFilter){
// return false;
// }
// })
// filtersSelected = {
// status : ['save_as_draft'],
// amount: [],
// expiry:[],
// };
// }
}
return true;
});
console.log(updatedDataArr);
}
updateData(data)
amountorexpiryfields. What are those filters supposed to do?