How can I minimize this code? because excel said it has more than 64 conditions - xlsx

note: those texts equivalent to $C$1 is a dropdown list.
=IF(
$C$1="", "", IF(
$C$1="AGLAYAN 1", T4, IF(
$C$1="AGLAYAN 2", AI4, IF(
$C$1="ALABEL", AX4, IF(
$C$1="BABAK 1",BM4,IF($C$1="BABAK 2",CB4,IF($C$1="BANAYBANAY",CQ4,IF($C$1="BANGA",DF4,IF($C$1="BANSALAN",DU4,IF($C$1="BANSALAN 2",EJ4,IF($C$1="BANSALAN 3",EY4,IF($C$1="BAROBO",FN4,IF($C$1="BATOBATO",GC4,IF($C$1="BAYUGAN",GR4,IF($C$1="BUHANGIN",HG4,IF($C$1="CALINAN",HV4,IF($C$1="CARMEN",IK4,IF($C$1="COMPOSTELA 1",IZ4,IF($C$1="COMPOSTELA 2",JO4,IF($C$1="CUGMAN",KD4,IF($C$1="DIGOS 1",KS4,IF($C$1="DIGOS 2",LH4,IF($C$1="DIGOS 3",LW4,IF($C$1="DON CARLOS 1",ML4,IF($C$1="ESPERANZA 1",NA4,IF($C$1="ESPERANZA 2",NP4,IF($C$1="ESPERANZA 3",OE4,IF($C$1="GENSAN",OT4,IF($C$1="HAGONOY",PI4,IF($C$1="HINATUAN",PX4,IF($C$1="ISULAN 1",QM4,IF($C$1="KABAKAN 1",RB4,IF($C$1="KABAKAN 2",RQ4,IF($C$1="KALILANGAN",SF4,IF($C$1="KAPALONG",SU4,IF($C$1="KIDAPAWAN 2",TJ4,IF($C$1="KIDAPAWAN 3",TY4,IF($C$1="KIDAPAWAN 4",UN4,IF($C$1="KIDAPAWAN 5",VC4,IF($C$1="KIDAPAWAN 6",VR4,IF($C$1="KIDAPAWAN 7",WG4,IF($C$1="KIDAPAWAN 8",WV4,IF($C$1="KRINKLES 1",XK4,IF($C$1="KRINKLES 2",XZ4,IF($C$1="LUPON 1",YO4,IF($C$1="LUPON 2",ZD4,IF($C$1="MAASIM",ZS4,IF($C$1="MAGPET",AAH4,IF($C$1="MAGSAYSAY",AAW4,IF($C$1="MAITUM",ABL4,IF($C$1="MAKILALA",ACA4,IF($C$1="MALAYBALAY",ACP4,IF($C$1="MALITA",ADE4,IF($C$1="MANGAGOY",ADT4,IF($C$1="MARAMAG 1",AEI4,IF($C$1="MARAMAG 2",AEX4,IF($C$1="MARBEL 1",AFM4,IF($C$1="MARBEL 2",AGB4,IF($C$1="MARIKIT",AGQ4,IF($C$1="MATALAM",AHF4,IF($C$1="MATANAO",AHU4,IF($C$1="MIDSAYAP",AIJ4,IF($C$1="MLANG",AIY4,IF($C$1="MONKAYO",AJN4,IF($C$1="NABUNTURAN 1",AKC4,IF($C$1="NABUNTURAN 2",AKR4,IF($C$1="NABUNTURAN 3",AKG4,IF($C$1="OZAMIZ",ALV4,IF($C$1="PADADA",AMK4,IF($C$1="PANABO 2",AMZ4,IF($C$1="PANABO 3",ANO4,IF($C$1="PANABO 5",AOD4,IF($C$1="PANABO MAIN",AOS4,IF($C$1="PANABO PDP 1",APH4,IF($C$1="PANABO PDP 2",APW4,IF($C$1="PANTUKAN",AQL4,IF($C$1="PEÑAPLATA",ARA4,IF($C$1="PIGKAWAYAN",ARP4,IF($C$1="POLOMOLOK 1",ASE4,IF($C$1="POLOMOLOK 2",AST4,IF($C$1="PUERTO",ATI4,IF($C$1="QUEZON",ATX4,IF($C$1="SAN FRANCISCO 1",AUM4,IF($C$1="STA. MARIA",AVB4,IF($C$1="STO NIÑO",AVQ4,IF($C$1="STO. TOMAS",AWF4,IF($C$1="SULOP",AWU4,IF($C$1="SURIGAO 2",AXJ4,IF($C$1="TACORONG 1",AXY4,IF($C$1="TACORONG 2",AYN4,IF($C$1="TAGBINA",AZC4,IF($C$1="TAGUM 4",AZR4,IF($C$1="TIBUNGCO 1",BAG4,IF($C$1="TIBUNGCO 2",BAV4,IF($C$1="TORIL 1",BBK4,IF($C$1="TORIL 2",BBZ4,IF($C$1="TRENTO",BCO4,IF($C$1="TULUNAN",BDD4,IF($C$1="TUPI",BDS4,""))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
)
)
)
)
)

Please try the following...
First, bring up the Worksheet_Change event's VBA code. To do this click somewhere in your woeksheet. Choose the Developer menu. Choose Design Mode. Choose View Code.
Next, paste in the following code...
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$1" Then
Select Case $C$1
Case "AGLAYAN 1"
Range( "E4:S19" ).Value = Range( "T4:AH19" ).Value
Case "AGLAYAN 2"
Range( "E4:S19" ).Value = Range( "AI4:AW19" ).Value
Case "ALABEL",
Range( "E4:S19" ).Value = Range( "AX4:BL19" ).Value
Case "BABAK 1",
Range( "E4:S19" ).Value = Range( "BM4:CA19" ).Value
Case "BABAK 2",
Range( "E4:S19" ).Value = Range( "CB4:CP19" ).Value
Case "BANAYBANAY",
Range( "E4:S19" ).Value = Range( "CQ4:DE19" ).Value
Case "BANGA",
Range( "E4:S19" ).Value = Range( "DF4:DT19" ).Value
Case "BANSALAN",
Range( "E4:S19" ).Value = Range( "DU4:EI19" ).Value
Case "BANSALAN 2",
Range( "E4:S19" ).Value = Range( "EJ4:EX19" ).Value
Case "BANSALAN 3",
Range( "E4:S19" ).Value = Range( "EY4:FM19" ).Value
Case "BAROBO",
Range( "E4:S19" ).Value = Range( "FN4:GB19" ).Value
Case "BATOBATO",
Range( "E4:S19" ).Value = Range( "GC4:GQ19" ).Value
Case "BAYUGAN",
Range( "E4:S19" ).Value = Range( "GR4:HF19" ).Value
Case "BUHANGIN", HG4,
Range( "E4:S19" ).Value = Range( "HG4:HU19" ).Value
Case "CALINAN",
Range( "E4:S19" ).Value = Range( "HV4:IJ19" ).Value
Case "CARMEN",
Range( "E4:S19" ).Value = Range( "IK4:IY19" ).Value
Case "COMPOSTELA 1",
Range( "E4:S19" ).Value = Range( "IZ4:JN19" ).Value
Case "COMPOSTELA 2",
Range( "E4:S19" ).Value = Range( "JO4:KC19" ).Value
Case "CUGMAN",
Range( "E4:S19" ).Value = Range( "KD4:KR19" ).Value
Case "DIGOS 1",
Range( "E4:S19" ).Value = Range( "KS4:LG19" ).Value
Case "DIGOS 2",
Range( "E4:S19" ).Value = Range( "LH4:LV19" ).Value
Case "DIGOS 3",
Range( "E4:S19" ).Value = Range( "LW4:MK19" ).Value
Case "DON CARLOS 1",
Range( "E4:S19" ).Value = Range( "ML4:MZ19" ).Value
Case "ESPERANZA 1",
Range( "E4:S19" ).Value = Range( "NA4:NO19" ).Value
Case "ESPERANZA 2",
Range( "E4:S19" ).Value = Range( "NP4:OD19" ).Value
Case "ESPERANZA 3",
Range( "E4:S19" ).Value = Range( "OE4:OS19" ).Value
Case "GENSAN",
Range( "E4:S19" ).Value = Range( "OT4:PH19" ).Value
Case "HAGONOY",
Range( "E4:S19" ).Value = Range( "PI4:PW19" ).Value
Case "HINATUAN",
Range( "E4:S19" ).Value = Range( "PX4:QL19" ).Value
Case "ISULAN 1",
Range( "E4:S19" ).Value = Range( "QM4:RA19" ).Value
Case "KABAKAN 1",
Range( "E4:S19" ).Value = Range( "RB4:RP19" ).Value
Case "KABAKAN 2",
Range( "E4:S19" ).Value = Range( "RQ4:SE19" ).Value
Case "KALILANGAN",
Range( "E4:S19" ).Value = Range( "SF4:ST19" ).Value
Case "KAPALONG",
Range( "E4:S19" ).Value = Range( "SU4:TI19" ).Value
Case "KIDAPAWAN 2",
Range( "E4:S19" ).Value = Range( "TJ4:TX19" ).Value
Case "KIDAPAWAN 3",
Range( "E4:S19" ).Value = Range( "TY4:UM19" ).Value
Case "KIDAPAWAN 4",
Range( "E4:S19" ).Value = Range( "UN4:VB19" ).Value
Case "KIDAPAWAN 5",
Range( "E4:S19" ).Value = Range( "VC4:VQ19" ).Value
Case "KIDAPAWAN 6",
Range( "E4:S19" ).Value = Range( "VR4:WF19" ).Value
Case "KIDAPAWAN 7",
Range( "E4:S19" ).Value = Range( "WG4:WU19" ).Value
Case "KIDAPAWAN 8",
Range( "E4:S19" ).Value = Range( "WV4:XJ19" ).Value
Case "KRINKLES 1",
Range( "E4:S19" ).Value = Range( "XK4:XY19" ).Value
Case "KRINKLES 2",
Range( "E4:S19" ).Value = Range( "XZ4:YN19" ).Value
Case "LUPON 1",
Range( "E4:S19" ).Value = Range( "YO4:ZC19" ).Value
Case "LUPON 2",
Range( "E4:S19" ).Value = Range( "ZD4:ZR19" ).Value
Case "MAASIM",
Range( "E4:S19" ).Value = Range( "ZS4:AAG19" ).Value
Case "MAGPET",
Range( "E4:S19" ).Value = Range( "AAH4:AAV19" ).Value
Case "MAGSAYSAY",
Range( "E4:S19" ).Value = Range( "AAW4:ABK19" ).Value
Case "MAITUM",
Range( "E4:S19" ).Value = Range( "ABL4:ABZ19" ).Value
Case "MAKILALA",
Range( "E4:S19" ).Value = Range( "ACA4:ACO19" ).Value
Case "MALAYBALAY",
Range( "E4:S19" ).Value = Range( "ACP4:ADD19" ).Value
Case "MALITA",
Range( "E4:S19" ).Value = Range( "ADE4:ADS19" ).Value
Case "MANGAGOY",
Range( "E4:S19" ).Value = Range( "ADT4:AEH19" ).Value
Case "MARAMAG 1",
Range( "E4:S19" ).Value = Range( "AEI4:AEW19" ).Value
Case "MARAMAG 2",
Range( "E4:S19" ).Value = Range( "AEX4:AFL19" ).Value
Case "MARBEL 1",
Range( "E4:S19" ).Value = Range( "AFM4:AGA19" ).Value
Case "MARBEL 2",
Range( "E4:S19" ).Value = Range( "AGB4:AGP19" ).Value
Case "MARIKIT",
Range( "E4:S19" ).Value = Range( "AGQ4:AHE19" ).Value
Case "MATALAM",
Range( "E4:S19" ).Value = Range( "AHF4:AHT19" ).Value
Case "MATANAO",
Range( "E4:S19" ).Value = Range( "AHU4:AII19" ).Value
Case "MIDSAYAP",
Range( "E4:S19" ).Value = Range( "AIJ4:AIX19" ).Value
Case "MLANG",
Range( "E4:S19" ).Value = Range( "AIY4:AJM19" ).Value
Case "MONKAYO",
Range( "E4:S19" ).Value = Range( "AJN4:AKB19" ).Value
Case "NABUNTURAN 1",
Range( "E4:S19" ).Value = Range( "AKC4:AKQ19" ).Value
Case "NABUNTURAN 2",
Range( "E4:S19" ).Value = Range( "AKR4:ALF19" ).Value
Case "NABUNTURAN 3",
Range( "E4:S19" ).Value = Range( "ALG4:ALU19" ).Value
Case "OZAMIZ",
Range( "E4:S19" ).Value = Range( "ALV4:AMJ19" ).Value
Case "PADADA",
Range( "E4:S19" ).Value = Range( "AMK4:AMY19" ).Value
Case "PANABO 2",
Range( "E4:S19" ).Value = Range( "AMZ4:ANNP19" ).Value
Case "PANABO 3",
Range( "E4:S19" ).Value = Range( "ANO4:AOC19" ).Value
Case "PANABO 5",
Range( "E4:S19" ).Value = Range( "AOD4:AOR19" ).Value
Case "PANABO MAIN",
Range( "E4:S19" ).Value = Range( "AOS4:APG19" ).Value
Case "PANABO PDP 1",
Range( "E4:S19" ).Value = Range( "APH4:APV19" ).Value
Case "PANABO PDP 2",
Range( "E4:S19" ).Value = Range( "APW4:AQK19" ).Value
Case "PANTUKAN",
Range( "E4:S19" ).Value = Range( "AQL4:AQZ19" ).Value
Case "PEÑAPLATA",
Range( "E4:S19" ).Value = Range( "ARA4:ARO19" ).Value
Case "PIGKAWAYAN",
Range( "E4:S19" ).Value = Range( "ARP4:ASD19" ).Value
Case "POLOMOLOK 1",
Range( "E4:S19" ).Value = Range( "ASE4:ASS19" ).Value
Case "POLOMOLOK 2",
Range( "E4:S19" ).Value = Range( "AST4:ATH19" ).Value
Case "PUERTO",
Range( "E4:S19" ).Value = Range( "ATI4:ATW19" ).Value
Case "QUEZON",
Range( "E4:S19" ).Value = Range( "ATX4:AUL19" ).Value
Case "SAN FRANCISCO 1",
Range( "E4:S19" ).Value = Range( "AUM4:AVA19" ).Value
Case "STA. MARIA",
Range( "E4:S19" ).Value = Range( "AVB4:AVP19" ).Value
Case "STO NIÑO",
Range( "E4:S19" ).Value = Range( "AVQ4:AWE19" ).Value
Case "STO. TOMAS",
Range( "E4:S19" ).Value = Range( "AWF4:AWT19" ).Value
Case "SULOP",
Range( "E4:S19" ).Value = Range( "AWU4:AXI19" ).Value
Case "SURIGAO 2",
Range( "E4:S19" ).Value = Range( "AXJ4:AXX19" ).Value
Case "TACORONG 1",
Range( "E4:S19" ).Value = Range( "AXY4:AYM19" ).Value
Case "TACORONG 2",
Range( "E4:S19" ).Value = Range( "AYN4:AZB19" ).Value
Case "TAGBINA",
Range( "E4:S19" ).Value = Range( "AZC4:AZQ19" ).Value
Case "TAGUM 4",
Range( "E4:S19" ).Value = Range( "AZR4:BAF19" ).Value
Case "TIBUNGCO 1",
Range( "E4:S19" ).Value = Range( "BAG4:BAU19" ).Value
Case "TIBUNGCO 2",
Range( "E4:S19" ).Value = Range( "BAV4:BBJ19" ).Value
Case "TORIL 1",
Range( "E4:S19" ).Value = Range( "BBK4:BBY19" ).Value
Case "TORIL 2",
Range( "E4:S19" ).Value = Range( "BBZ4:BCN19" ).Value
Case "TRENTO",
Range( "E4:S19" ).Value = Range( "BCO4:BDC19" ).Value
Case "TULUNAN",
Range( "E4:S19" ).Value = Range( "BDD4:BDR19" ).Value
Case "TUPI",
Range( "E4:S19" ).Value = Range( "BDS4:BEG19" ).Value
Case Else
Range( "E4" ).Value = "Error encountered"
End If
End Sub
Finally, choose Close and Return to Microsoft Excel from the File menu.
If you have any questions or comments, then please feel free to post a Comment accordingly.

Related

how to remove a field from a dart list without affecting main list

I want to remove the id field from datacopy list. but when I do it, also data list is updated. I want to remove the id field only from datacopy list. how to do that?
void main() {
List<Map<String, dynamic>> data = [
{
'id': '1',
'domain': '00extreme.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 00 ] [ extreme ]'
},
{
'id': '2',
'domain': '00hrs.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 00 ] [ hrs ]'
},
{
'id': '3',
'domain': '00k3.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 00 ] [ k ] [ 3 ]'
},
{
'id': '4',
'domain': '00I.net',
'TDL': 'net',
'status': 'parked',
'adult': 'No',
'keywords': '[ 00I.net ]'
},
{
'id': '5',
'domain': '02text.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 02 ] [ text ]'
},
{
'id': '6',
'domain': '0zzy.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 0 ] [ zz ] [ y ]'
},
{
'id': '7',
'domain': '100facial.com',
'TDL': 'com',
'status': 'parked',
'adult': 'Yes',
'keywords': '[ 100 ] [ facial ]'
},
{
'id': '8',
'domain': '1000fotosgratis.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 1000 ] [ fotos ] [ gratis ]'
},
{
'id': '9',
'domain': '1000petstores.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 1000 ] [ pet ] [ stores ]'
},
{
'id': '10',
'domain': '1000toys.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 100 ] [ toys ]'
},
];
List<Map<String, dynamic>> datacopy =[];
datacopy = [...data];
removeItem(String key) {
datacopy.map((element) {
var m = element;
m.remove(key);
return m;
}).toList();
}
removeItem('id');
print(data);
print(datacopy);
}
I want to remove the id field from datacopy list. but when I do it, also data list is updated. I want to remove the id field only from datacopy list. how to do that?
I think the inner map also passing as reference. You can create new map.
datacopy.addAll(data.map((e) => Map.from(e)));
for (final item in datacopy) {
item.remove("id");
}
print(data);
print("NA\n");
print(datacopy);
Try the following code:
void main() {
List<Map<String, dynamic>> data = [
{
'id': '1',
'domain': '00extreme.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 00 ] [ extreme ]'
},
{
'id': '2',
'domain': '00hrs.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 00 ] [ hrs ]'
},
{
'id': '3',
'domain': '00k3.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 00 ] [ k ] [ 3 ]'
},
{
'id': '4',
'domain': '00I.net',
'TDL': 'net',
'status': 'parked',
'adult': 'No',
'keywords': '[ 00I.net ]'
},
{
'id': '5',
'domain': '02text.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 02 ] [ text ]'
},
{
'id': '6',
'domain': '0zzy.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 0 ] [ zz ] [ y ]'
},
{
'id': '7',
'domain': '100facial.com',
'TDL': 'com',
'status': 'parked',
'adult': 'Yes',
'keywords': '[ 100 ] [ facial ]'
},
{
'id': '8',
'domain': '1000fotosgratis.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 1000 ] [ fotos ] [ gratis ]'
},
{
'id': '9',
'domain': '1000petstores.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 1000 ] [ pet ] [ stores ]'
},
{
'id': '10',
'domain': '1000toys.com',
'TDL': 'com',
'status': 'parked',
'adult': 'No',
'keywords': '[ 100 ] [ toys ]'
},
];
List<Map<String, dynamic>> datacopy =[];
addData() {
datacopy.addAll(data);
}
addData();
removeItem(String key) {
datacopy.map((element) {
var m = element;
m.remove(key);
return m;
}).toList();
}
removeItem('id');
print(data);
print(datacopy);
}

Create this type of array

This is what I want:
[
{ value: '1', label: 'LABEL 1' },
{ value: '2', label: 'LABEL 2' },
{ value: '3', label: 'LABEL 3' },
{ value: '4', label: 'LABEL 4' },
]
Currently I have this, but seems not working. The namesToSearch return an array of names.
const increment = ['1', '2', '3', '4']
const RequiredData = [{
value: increment,
label: namesToSearch,
}]
this.setState({ namesToSearch: RequiredData })
This output something like:
[…]
0: {…}
label: (3) […]
0: "label 1"
1: "label 2"
2: "label 3"
value: (4) […]
0: "1"
1: "2"
2: "3"
3: "4"
Try this:
const increment = ['1', '2', '3', '4'];
const RequiredData = increment.map((value, index) => ({
value,
label: namesToSearch[index],
}));
this.setState({ namesToSearch: RequiredData });

Filter Array of Object from another Array of Object

Currently I'm filtering data based from questions that have checked property value equals to true..
const data = [
{Name: "foo", X1: "1", X2: "1", Other: "Test1"},
{Name: "bar", X1: "2",X2: "2",Other: "Test2"},
{Name: "test",X1: "2",X2: "3",Other: "Test3"}
];
const questions = [{rows: {text: "Text 1", checked: true,fields: "1",column: "X1"}
}, {rows: {text: "Text 2", checked: true,fields: "2",column: "X1"}
}, {rows: {text: "Text 3", checked: false,fields: "1",column: "X2"}
}, {rows: {text: "Text 4", checked: false,fields: "2",column: "X2"}
}, {rows: {text: "Text 5", checked: false,fields: "3",column: "X2"}
}];
console.log(questionArr);
// console.log(dataArr);
const res = data.filter(d => questions.find(f => d[f.rows.column] === f.rows.fields && f.rows.checked));
which works but does not work when filtering the actual data below. I think there's a slight difference between the question object and the actual question object below.. What should be my filter code when accessing these kind of structure ?
I think this is what you're looking for. I matched the data structure to the image in your question. Let me know if I missed something.
const data = [
{ Name: "foo", X1: "1", X2: "1", Other: "Test1" },
{ Name: "bar", X1: "2", X2: "2", Other: "Test2" },
{ Name: "test", X1: "2", X2: "3", Other: "Test3" }
];
const questions = [
{ rows: [{ text: "Text 1", checked: true, fields: "2", column: "X1" }] },
{ rows: [{ text: "Text 2", checked: true, fields: "2", column: "X1" }] },
{ rows: [{ text: "Text 3", checked: false, fields: "1", column: "X2" }] },
{ rows: [{ text: "Text 4", checked: false, fields: "2", column: "X2" }] },
{ rows: [{ text: "Text 5", checked: false, fields: "3", column: "X2" }] }
];
const result = data.filter(function(item){
return questions.some(function(question){
return question.rows.some(function(row){
return (row.checked && item[row.column] === row.fields);
});
});
});
console.log(result);
The compact version
const result = data.filter((item) => questions.some((question) => question.rows.some((row) => (row.checked && item[row.column] === row.fields))));
With perf in mind
const data = [
{ Name: "foo", X1: "1", X2: "1", Other: "Test1" },
{ Name: "bar", X1: "2", X2: "2", Other: "Test2" },
{ Name: "test", X1: "2", X2: "3", Other: "Test3" }
];
const questions = [
{ rows: [{ text: "Text 1", checked: true, fields: "2", column: "X1" }] },
{ rows: [{ text: "Text 2", checked: true, fields: "2", column: "X1" }] },
{ rows: [{ text: "Text 3", checked: false, fields: "1", column: "X2" }] },
{ rows: [{ text: "Text 4", checked: false, fields: "2", column: "X2" }] },
{ rows: [{ text: "Text 5", checked: false, fields: "3", column: "X2" }] }
];
const result = {};
for(let a = 0, b = data.length; a < b; a++){
const item = data[a];
for(let c = 0, d = questions.length; c < d; c++){
const rows = questions[c].rows;
for(let e = 0, f = rows.length; e < f; e++){
const row = rows[e];
if(row.checked && item[row.column] === row.fields){
result[item.Name] = item;
break;
}
}
}
}
// this could be replaced with Object.values(result);
const matches = [];
for(let match in result){
matches.push(result[match]);
}
// not supported by IE yet
// Object.values(result);
console.log(matches);

UI Grid - from JavaScript to Typescript

I am fairly new to Angular and just recently constructed this UI Grid table. I used several code examples on the tutorial site at http://ui-grid.info/docs/#!/tutorial to build mine. So basically its just the app.js (please see my code below) that I was tasked to convert from Angular JavaScript to Typescript. But since I am new to Angular and Typescript and learn best by example (still going through intro tutorials on Plurasight.com), I need to see one in order to understand how to go about it.
Is there any chance someone could point me to a Plunker link or any other source where I could see an example of Typescript-based code of the app.js/app.ts for UI Grid? I'd greatly appreciate any help!
Actual CODE
var app = angular.module('app', ['ngAnimate', 'ngTouch', 'ui.grid', 'ui.grid.saveState', 'ui.grid.selection', 'ui.grid.cellNav', 'ui.grid.edit', 'ui.grid.pinning', 'ui.grid.grouping', 'ui.grid.exporter']);
app.controller('MainCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.gridOptions = {
enableCellEditOnFocus: true,
enableFiltering: true,
columnDefs: [
{ name: 'skunumber', displayName: 'SKU Number', enableCellEdit: true, width: '125' },
{ name: 'description', displayName: 'SKU Description', enableCellEdit: true, width: '145' },
{ name: 'averagecost', displayName: 'Cost', enableCellEdit: true, width: '65' },
{ name: 'regularretail', displayName: 'Retail', enableCellEdit: true, width: '75' },
{ name: 'saleprice', displayName: 'Sale Price', enableCellEdit: true, width: '100' },
{ name: '%offretail', displayName: '% Off', enableCellEdit: true, width: '75' },
{ name: '$offretail', displayName: '$ Off', enableCellEdit: true, width: '70' },
{ name: 'savings', displayName: 'Savings', enableCellEdit: true, width: '100' },
{ name: 'projunits', displayName: 'Projected Units', enableCellEdit: true, width: '140' },
{ name: 'scandown', displayName: 'Scan $', enableCellEdit: true, width: '75' },
{ name: 'page', displayName: 'Page', type: 'number', width: '65' },
{ name: 'group', displayName: 'Group', type: 'number', width: '75' },
{
name: 'pickup', displayName: 'PickUp', editableCellTemplate: 'ui-grid/dropdownEditor', width: '85',
cellFilter: 'mapPickup', editDropdownValueLabel: 'pickup', editDropdownOptionsArray: [
{ id: 1, pickup: 'S' },
{ id: 2, pickup: 'VI' },
{ id: 3, pickup: 'N/A' }
]
},
{
name: 'adcopy', displayName: 'Ad Copy', editableCellTemplate: 'ui-grid/dropdownEditor', width: '125',
cellFilter: 'mapAdcopy', editDropdownValueLabel: 'adcopy', editDropdownOptionsArray: [
{ id: 1, adcopy: 'Asst.' },
{ id: 2, adcopy: 'Asst. sizes' },
{ id: 3, adcopy: 'Asst. sizes and colors' },
{ id: 4, adcopy: 'Asst. sizes and counts' },
{ id: 5, adcopy: 'Asst. styles' },
{ id: 6, adcopy: 'Big Men sizes $1 more' },
{ id: 7, adcopy: 'Big Men sizes $2 more' },
{ id: 8, adcopy: 'BOGO' },
{ id: 9, adcopy: 'BOGO 50%' },
{ id: 10, adcopy: 'BTGT for $' },
{ id: 11, adcopy: 'BTGT FREE' },
{ id: 12, adcopy: 'Buy this many _, Get for $' },
{ id: 13, adcopy: 'Buy this many _, Get this many _ free' },
{ id: 14, adcopy: 'Compare at' },
{ id: 15, adcopy: 'Coupon Item' },
{ id: 16, adcopy: 'Limited Qty.' },
{ id: 17, adcopy: 'Local Low Price' },
{ id: 18, adcopy: 'Low Price Leader' },
{ id: 19, adcopy: 'New # Freds' },
{ id: 20, adcopy: 'Own Brand Compare and save' },
{ id: 21, adcopy: 'Plus sizes $1 more' },
{ id: 22, adcopy: 'Plus sizes $2 more' },
{ id: 23, adcopy: 'Primary Sale Item' },
{ id: 24, adcopy: 'SCREAMING LOW PRICE ITEM' },
{ id: 25, adcopy: 'Styles vary by store' },
{ id: 26, adcopy: 'While supplies last' },
{ id: 27, adcopy: 'Your Choice' }
]
}
],
exporterLinkLabel: 'get your csv here',
exporterPdfDefaultStyle: { fontSize: 9 },
exporterPdfTableStyle: { margin: [30, 30, 30, 30] },
exporterPdfTableHeaderStyle: { fontSize: 10, bold: true, italics: true, color: 'red' },
exporterPdfOrientation: 'landscape',
exporterPdfPageSize: 'LETTER',
exporterPdfMaxGridWidth: 500,
exporterHeaderFilter: function (displayName) {
if (displayName === 'skunumber') {
return 'SKU Number';
} else {
return displayName;
}
},
exporterFieldCallback: function (grid, row, col, input) {
if (col.name == 'pickup') {
switch (input) {
case 1:
return 'S';
break;
case 2:
return 'VI';
break;
default:
return 'N/A';
break;
}
}
if (col.name == 'adcopy') {
switch (input) {
case 1:
return 'Asst.';
break;
case 2:
return 'Asst. sizes';
break;
case 3:
return 'Asst. sizes and colors';
break;
case 4:
return 'Asst. sizes and counts';
break;
case 5:
return 'Asst. styles';
break;
case 6:
return 'Big Mens sizes $1 more';
break;
case 7:
return 'Big Mens sizes $2 more';
break;
case 8:
return 'BOGO';
break;
case 9:
return 'BOGO 50%';
break;
case 10:
return 'BTGT for $';
break;
case 11:
return 'BTGT free';
break;
case 12:
return 'Buy this many _, Get for $';
break;
case 13:
return 'Buy this many _, Get this many _ free';
break;
case 14:
return 'Compare at';
break;
case 15:
return 'Coupon Item';
break;
case 16:
return 'Limited Qty.';
break;
case 17:
return 'Local Low Price';
break;
case 18:
return 'Low Price Leader';
break;
case 19:
return 'New # Freds';
break;
case 20:
return 'Own Brand Compare and save';
break;
case 21:
return 'Plus sizes $1 more';
break;
case 22:
return 'Plus sizes $2 more';
break;
case 23:
return 'Primary Sale Item';
break;
case 24:
return 'SCREAMING LOW PRICE ITEM';
break;
case 25:
return 'Styles vary by store';
break;
case 26:
return 'While supplies last';
break;
default:
return 'Your Choice';
break;
}
} else {
return input;
}
},
onRegisterApi: function (gridOptions) {
$scope.gridOptions = gridOptions;
}
};
$http.get('../../data/global.json')
.then(function (response) {
var data = response.data;
for (i = 0; i < data.length; i++) {
data[i].registered = new Date(data[i].registered);
data[i].pickup = data[i].pickup === 'N/A' ? 1 : 3;
data[i].adcopy = data[i].adcopy === 'Your Choice' ? 1 : 27;
}
$scope.gridOptions.data = data;
});
// ADD NEW ROW
$scope.addSku = function () {
var n = $scope.gridOptions.data.length + 1;
$scope.gridOptions.data.push({
"skunumber": n++,
"description": "SKU description " + n,
"averagecost": "$" + n + ".00",
"regularretail": "$" + n + ".00",
"page": n,
"group": n,
"pickup": " ",
"adcopy": " ",
"costoverride": "$" + n + ".00",
"retailoverride": "$" + n + ".00",
"adunitsper": n,
"retailunitsper": n,
"saleprice": "$" + n + ".00",
"%offretail": "%" + n,
"$offretail": "$" + n + ".00",
"savings": "$" + n + ".00",
"scandown": "$" + n + ".00",
"combopriceper": "$" + n + ".00",
"combosaleprice": "$" + n + ".00",
"comboscandown": "$" + n + ".00",
"estneedbreakout": n,
"jdareplenished": true,
"raincheck": true,
"shelftalker": true,
"eventsign": true,
"projunits": n,
"projected": "$" + n + ".00"
});
};
// DELETE SELECTED
$scope.deleteSku1 = function () {
angular.forEach($scope.gridOptions.selection.getSelectedRows(), function (data, index) {
$scope.gridOptions.data.splice($scope.gridOptions.data.lastIndexOf(data), 1);
});
};
// DELETE SELECTED - SET GRID API ON SCOPE
$scope.gridOptions.onRegisterApi = function (deleteSelected) {
$scope.gridOptions = deleteSelected;
deleteSelected.selection.on.rowSelectionChanged($scope, function (row) {
});
};
// REMOVE TOP ROW
$scope.removeFirstRow1 = function () {
$scope.gridOptions.data.splice(0, 1);
};
$scope.state = {};
// SAVE & RESTORE STATE
// gridOptions SAVE
$scope.gridOptions.saveState = function () {
$scope.state = $scope.gridOptions.saveState.save();
};
// gridOptions RESTORE
$scope.gridOptions.restoreState = function () {
$scope.gridOptions.saveState.restore($scope, $scope.state);
};
$scope.export = function () {
if ($scope.export_format == 'csv') {
var myElement = angular.element(document.querySelectorAll(".custom-csv-link-location"));
$scope.gridOptions.exporter.csvExport($scope.export_row_type, myElement);
} else if ($scope.export_format == 'pdf') {
$scope.gridOptions.exporter.pdfExport($scope.export_row_type);
}
};
}])
.filter('mapPickup', function () {
var pickupHash = {
1: 'S',
2: 'VI',
3: 'N/A'
};
return function (input) {
if (!input) { return 'pickup'; }
else { return pickupHash[input]; }
};
})
.filter('mapAdcopy', function () {
var adcopyHash = {
1: 'Asst.',
2: 'Asst. sizes',
3: 'Asst. sizes and colors',
4: 'Asst. sizes and counts',
5: 'Asst. styles',
6: 'Big Mens sizes $1 more',
7: 'Big Mens sizes $2 more',
8: 'BOGO',
9: 'BOGO 50%',
10: 'BTGT for $',
11: 'BTGT free',
12: 'Buy this many _, Get for $',
13: 'Buy this many _, Get this many _ free',
14: 'Compare at',
15: 'Coupon Item',
16: 'Limited Qty.',
17: 'Local Low Price',
18: 'Low Price Leader',
19: 'New # Freds',
20: 'Own Brand Compare and save',
21: 'Plus sizes $1 more',
22: 'Plus sizes $2 more',
23: 'Primary Sale Item',
24: 'SCREAMING LOW PRICE ITEM',
25: 'Styles vary by store',
26: 'While supplies last',
27: 'Your Choice'
};
return function (input) {
if (!input) { return 'adcopy'; }
else { return adcopyHash[input]; }
};
});

Trouble getting angular-google-chart to produce dual axis chart

I am having trouble getting angular-google-chart to produce a chart with two y-axis scales. I have tried numerous example from online that work with google chart directly but have had no luck. I have included what I believe to be a simple example. This code is inside a controller. Here is my code:
(function () {
'use strict';
angular
.module('core')
.controller('DashboardErrorRatesController', DashboardErrorRatesController);
DashboardErrorRatesController.$inject = ['$rootScope', '$scope', '$state', '$timeout', '$interval', 'Authentication', 'locale', 'Common', 'Query', 'googleJsapiUrl'];
function DashboardErrorRatesController($rootScope, $scope, $state, $timeout, $interval, Authentication, locale, Common, Query, googleJsapiUrl) {
$scope.myChartObject = {
type: 'LineChart',
displayed: false,
chartArea: { left: 100, top: 100, width: 400, height: 450 },
data: {
cols: [
{
id: 'issues',
label: 'Issues per Week',
type: 'string'
},
{
id: 'pct_people',
label: '% of People',
type: 'number'
},
{
id: 'avg_excallations',
label: 'Average Escallations',
type: 'number'
}
],
rows: [
{ 'c': [{ 'v': '0' }, { 'v': 0.39 }, { 'v': 0 }] },
{ 'c': [{ 'v': '1' }, { 'v': 0.17 }, { 'v': 31.063636363636363 }] },
{ 'c': [{ 'v': '2' }, { 'v': 0.12 }, { 'v': 30.46086956521739 }] },
{ 'c': [{ 'v': '3' }, { 'v': 0.09 }, { 'v': 49.612360674157316 }] },
{ 'c': [{ 'v': '4' }, { 'v': 0.06 }, { 'v': 26.975 }] },
{ 'c': [{ 'v': '5' }, { 'v': 0.04 }, { 'v': 32.82588235294117 }] },
{ 'c': [{ 'v': '6' }, { 'v': 0.03 }, { 'v': 25.413886666666667 }] },
{ 'c': [{ 'v': '7' }, { 'v': 0.03 }, { 'v': 35.716933333333344 }] },
{ 'c': [{ 'v': '8' }, { 'v': 0.02 }, { 'v': 11.689516129032258 }] },
{ 'c': [{ 'v': '9' }, { 'v': 0.01 }, { 'v': 10.20833125 }] },
{ 'c': [{ 'v': '10' }, { 'v': 0.01 }, { 'v': 29.311111111111114 }] },
{ 'c': [{ 'v': '10+' }, { 'v': 0.05 }, { 'v': 24.697815555555554 }] }
],
options: {
title: 'Something',
isStacked: false,
width: 300,
height: 600,
vAxis: {
0: {
title: '% of People',
format: '#%'
},
1: {
title: 'Average Escallations',
format: '#,###.##'
}
},
hAxis: {
title: 'Issues per Week'
},
seriesType: 'bars',
series: {
0: { targetAxisIndex: 0 },
1: { targetAxisIndex: 1 }
}
},
formatters: {}
}
};
}
}());
I think this should produce a chart with both axis, but nope. It is almost as the angular-google-chart library (0.1.0) is using an old version of google chart but I cannot figure that out.
And here is the html:
<div google-chart chart="myChartObject"></div>
I figured it out! I changed the type from 'LineChart' to 'ComboChart'. Whew that took a long time. I hate when that happens.
Look out for the vAxes keyword needing to be used when dealing with multiple axis(s). Took me a while to track this down.

Resources