Append external js data to grid by using tree item names

I have an external file that has a collection of data:

U_13_HTS=[
	   ["13 HTS","Radford","A-000001","1230000010","1909","Baseline","Yes","Yes","2019"],
	   ["13 HTS","Radford","A-000002","1230000011","1909","Baseline","Yes","Yes","2019"]
             ]

U_215_GP=[
	   ["215 GP","Sacramento","A-000005","1230000077","1909","Baseline","Yes","Yes","2019"],
	   ["215 GP","Sacramento","A-000006","1230000078","1909","Baseline","Yes","Yes","2019"],
	   ["215 GP","Sacramento","A-000007","1230000079","1909","Baseline","Yes","Yes","2019"]
             ]

I have a tree with a list of items that are array names in the external file and I collect them from the tree by using:

  str = myTree.getAllChecked(); 

Result is a coma delimited string - example : U_13_HTS,U_215_GP

I am trying to simulate async database calls without having a database…I would like to use the checked item string and map to the array collections in the external javascript file (See above array examples)

The following code works but it is hardcoded…how do I dynamically allow the .concat to accept the tree array that contains the array names that store the data need3ed to populate the grid?

Code:

	U_13_HTS=[
		   ["13 HTS","Radford","A-000001","1230000010","1909","Baseline","Yes","Yes","2019"],
		   ["13 HTS","Radford","A-000002","1230000011","1909","Baseline","Yes","Yes","2019"]
         ]

	U_215_GP=[
		   ["215 GP","Sacramento","A-000005","1230000077","1909","Baseline","Yes","Yes","2019"],
		   ["215 GP","Sacramento","A-000006","1230000078","1909","Baseline","Yes","Yes","2019"],
		   ["215 GP","Sacramento","A-000007","1230000079","1909","Baseline","Yes","Yes","2019"]
         ]

 str = myTree.getAllChecked();

 arr = str.split(",");

 merged = [].concat.apply([], [U_13_HTS,U_215_GP]);

 myGrid_Win_01.parse(merged,"jsarray");
  • Edited: static example
    Thanks

Ended up trying to use eval function but if records are past 10k then it’s worthless…ultimately I ended up using stringify on the arrays in a loop and concatenating on each iteration…I have around 40k records or 300 arrays with variable amount of records per array and if I check all 300 in tree it renders in about a second…with enablesmartrendering mode set on the grid

Code: Eval no loop (Not recommended) … especially if over 10k rows

   str = "U_13_HTS,U_215_GP,U_15_GP" 

   data = [].concat.apply([], eval( '[' + str + ']' ))   

 	myGrid_SDC.parse(data,"jsarray"); 

Code: Loop (Very fast)

   var check = myTree.getAllChecked();
   var arr = check.split(",")
   var str = "";
   var j;
   var k;

   for (i = 0; i < arr.length; i++) 
        {
          str = arr[i];

          try {
               // check if an array
               Array.isArray(eval(str))    
            
               // convert and modify string
       	   j = JSON.stringify(eval(str));           
		   j = j.replace("[[","[")
		   j = j.replace("]]","]")

    	   k += j                
              }

           catch (err) {     
                    // if not an array remove from string                                          
                    check = check.replace(","+ str,"")
                    check = check.replace(str,"")
			}        
          }

   // sanitize string and modify for parse
   data = "[" + k.replace("[object Object]","") + "]"   

   // simulate database connection (loading)... remove if desired
   setTimeout(function()
    { 
        
      try {              
           myGrid.parse(data,"jsarray"); 
           myStatusbar.setText("Record total: " + myGrid.getRowsNum());
 
           w1.progressOff()
           return;
          }
       catch (err) {
                     myStatusbar.setText("Record total: " + myGrid.getRowsNum());
                     w1.progressOff()
                     return;                        
                    }               
     }, 1000);