define({
//Type your controller code here
onNavigate:function(){
this.view.btnSearch.onClick =this.Dynseg;
this.view.txtsearch.onTextChange =this.ontxtDynseg;
this.view.txtsearch.text="";
this.Dynseg();
},
ontxtDynseg:function(){
if(this.view.txtsearch.text.trim().length === 0)
{
this.Dynseg();
}
},
Dynseg:function(){
var data = [
{
"imgProfile": "steve.png",
"imgRightArrow": "calright.png",
"lblAcountName": "zenny thomas",
"lblBeneficiaryName": "benny"
}, {
"imgProfile": "steve.png",
"imgRightArrow": "calright.png",
"lblAcountName": "benny thomas",
"lblBeneficiaryName": "benny"
}, {
"imgProfile": "steve.png",
"imgRightArrow": "calright.png",
"lblAcountName": "venny thomas",
"lblBeneficiaryName": "benny"
}, {
"imgProfile": "",
"imgRightArrow": "calright.png",
"lblAcountName": "benny thomas",
"lblBeneficiaryName": "benny"
}, {
"imgProfile": "steve.png",
"imgRightArrow": "calright.png",
"lblAcountName": "benny thomas",
"lblBeneficiaryName": "benny"
},{
"imgProfile": "steve.png",
"imgRightArrow": "calright.png",
"lblAcountName": "Ana thomas",
"lblBeneficiaryName": "benny"
}, {
"imgProfile": "steve.png",
"imgRightArrow": "calright.png",
"lblAcountName": "Honey thomas",
"lblBeneficiaryName": "benny"
}, {
"imgProfile": "steve.png",
"imgRightArrow": "calright.png",
"lblAcountName": "Enna thomas",
"lblBeneficiaryName": "benny"
}, {
"imgProfile": "steve.png",
"imgRightArrow": "calright.png",
"lblAcountName": "benny thomas",
"lblBeneficiaryName": "benny"
}, {
"imgProfile": "",
"imgRightArrow": "calright.png",
"lblAcountName": "Welcome thomas",
"lblBeneficiaryName": "benny"
}
];
var arr3 =[];
arr3 = data;
// var length = arr3.length;
var sData = [];
for (var ii = 0; ii < arr3.length; ii++) {
if (arr3[ii].lblAcountName !== null || arr3[ii].lblAcountName !== undefined) {
var txt1 = "";
if (arr3[ii].lblAcountName !== null && arr3[ii].lblAcountName !== undefined) {
txt1 = arr3[ii].lblAcountName;
}
var pattern = this.view.txtsearch.text.trim().toUpperCase();
if (txt1.toUpperCase().search(pattern) !== -1) {
sData.push(arr3[ii]);
}
}
}
if(sData.length > 0){
const transformed = {
data:[]
};
const findByLetter = (letter) => (element) => element.letter === letter;
for(let i = 0; i < sData.length; i++){
const letter = sData[i].lblAcountName.split("")[0];
const elIndex = transformed.data.findIndex(findByLetter(letter));
if(elIndex > -1){
transformed.data[elIndex].idata.push(data[i]);
}else{
transformed.data.push({
letter,
idata: [sData[i]],
});
}
}
transformed.data=transformed.data.sort((a, b) => a.letter.localeCompare(b.letter));
// const newArray= transformed.data.map(element=>[element.letter,element.idata]);
const newArray= transformed.data.map(element=>[{"flxsecHdrTemp":{skin:"sknflxSecHdrbg463faf"},"letter":{isVisible:true,text:element.letter}},element.idata]);
this.view.segLst.removeAll();
this.view.segLst.setData(newArray);
this.view.segLst.setVisibility(true);
this.view.lblnodatafnd.isVisible=false;
}else{
this.view.segLst.removeAll();
this.view.segLst.setVisibility(false);
this.view.lblnodatafnd.isVisible=true;
}
this.view.forceLayout();
}
});