kendo spreadsheet data return

hey guys. looking for a better solution. I am using kendo spreadsheet.  I need my data to return to a certain row. trying to make this happen dynamically.

Not to sure to go about this but looking for some great mines that will help in this case.
have a foreach loop. when a title is found the append json data. for this case 2 rows  but the way the format returns for this spreadsheet does not return correctly for more than one row. not sure.
    $scope.mysiz = []
angular.forEach($scope.get, function(value) {
            if (value.rowTitle == 'Meanze') {
                valuesM2 = ([value.current, '', value.cal, '', value.traili, ''
               , value.t, '', value.trail, '', value.tr]);
  $scope.mysiz +=valuesM2;
            }
        }, log);
         sheet.range("C9:M19").values($scope.mysize);


var Return as= [
            [ "1.3,1.3,-2.2,4.5,5.0,4.61.0,0.6,-2.9,4.1,4.8,4.2 ]
        ];

var Need to return as this format, because of brackets.= [
            [ "1.3,1.3,-2.2,4.5 ],
            [ "2",  8,  9, "3",  8,  9  ],
            [ "5",  6,  4,  "65", 4, 9  ]
        ];

Open in new window

LVL 9
Seven priceFull StackAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Julian HansenConnect With a Mentor Commented:
referring to it as "this" is a break in style
Well, you will need to take that up with the Angular team

The example was provided for clarity given the use of the log variable in the original code. It could just as easily have been expressed as the following with the same result. Note the removal of the log parameter and the change of this to log in the iteration function
      var log = [];
      angular.forEach($scope.get, function(value) {
        if (value.rowTitle == 'Meanze') {
          var valuesM2 = [
            value.current, 
            '', 
            value.cal, 
            '', 
            value.traili, 
            '', 
            value.t, 
            '', 
            value.trail, 
            '', 
            value.tr
          ];
          log.push(valuesM2);
        }
      });
      $scope.mysiz = log;

Open in new window

0
 
BigRatConnect With a Mentor Commented:
You are actually creating a row of objects, each object being nothing more than an array. The following code creates a two dimensional matrix. I haven't a clue of why you include formatting strings in the data, nor do I know anything about "kendo" spreadsheets. But one thing is certain, updating scope each time in a loop is a performance bottleneck. Also updating globals is not very performant, so a bit of functional programming would not go a miss. The function formatData() takes the data and returns a matrix which is directly assigned to scope, so the rebuilding of the HTML DOM takes place only one. One last point. Why is the "get" data in $scope?

function formatData(data) {
   var matrix = [];
   angular.forEach(data,function(value) {
      if(value.rowTitle==='Meanze') {
         var thisRow = [value.current, '', value.cal, '', value.traili, ''
               , value.t, '', value.trail, '', value.tr];
         matrix.push(thisRow);
      };
   });
   return matrix;
}

  $scope.matrix = formatData($scope.get);
 

Open in new window

0
 
Julian HansenCommented:
To expand on BigRat's solution you could also have done the following.
In your code you specified the context parameter log - but you don't seem to be using it. The following code demonstrates how you can use the context parameter to assign the rows to the return array
      var log = [];
      angular.forEach($scope.get, function(value) {
        if (value.rowTitle == 'Meanze') {
          var valuesM2 = [
            value.current, 
            '', 
            value.cal, 
            '', 
            value.traili, 
            '', 
            value.t, 
            '', 
            value.trail, 
            '', 
            value.tr
          ];
          // THE CONTEXT PARAMETER (log) BECOMES 'this' IN THE 
          // ITERATOR FUNCTION
          this.push(valuesM2);
        }
      }, log);
      $scope.mysiz = log;

Open in new window

1
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Seven priceFull StackAuthor Commented:
Thats great. ok I done some testing and the problem is when i push it creates as on long json for example.

i get
'13,15,-2.2,4.5,5.0,4.6,1.0,0.6,-2.9,4.1,4.8,4.2,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA'

Open in new window


But for each for loop it should create a new row not one long string. What could I do about this.
0
 
Seven priceFull StackAuthor Commented:
for a better exAMPLE i need to have my json return in this format.
 var values = [
            [ "C 1", "C 2", "C 3" ],
            [ new Date(2000, 10, 10), 5, 6 ],
            [ new Date(2010, 10, 10), 8, 9 ],
            [ null,                   8, 9 ],
            [ new Date(2000, 1, 1),   3, 9 ]
        ];

Open in new window

0
 
Seven priceFull StackAuthor Commented:
There is no get in the scope, just an example. Thanks guys.  The array is creating one open array instead of breaking each row into multiply arrays
0
 
Julian HansenCommented:
Please post your code. The code I posted earlier does not create one long array.
0
 
BigRatCommented:
Just as a matter of interest, Julian, what is "this" in line 19 of your code?

http://justjs.com/posts/this-considered-harmful
0
 
Julian HansenCommented:
@BigRat - this refers to the log (context) parameter to the forEach function
Refer Angular forEach

Specifically
Arguments
Param       Type         Details
obj         ObjectArray  Object to iterate over.
iterator    Function     Iterator function.
context     Object       Object to become context (this) for the iterator function.
(optional)

Open in new window

0
 
Julian HansenCommented:
Further to the above. The OP included the log parameter in his original source but never used it - I provided an example to show how it could be used (assumed he copied it from somewhere - wanted to put it in context so to speak).
0
 
BigRatCommented:
I personally find "this" very confusing. In the forEach case one has to think twice about it, because in any other context it would be completely different. The problem is always, that when somebody takes your code, mangles it, they might forget what exactly "this" was and as a consequence it would end up being miss-used. Given the fact that sevensnake77 now gets a single dimensional array a "this.push()" is highly likely to have produced that if he had mangled your code. "log" was probably there due to copying and probably referred to logging "if(log) log.write(...)" sort of thing.

If I may be permitted to quote Gwendolen, a girl after my own heart : " In matter of grave importance it is style which is the thing". Which is why passing a variable called log, which is really a matrix and referring to it as "this" is a break in style.
0
 
BigRatCommented:
Well, you will need to take that up with the Angular team

Well, they don't listen to old rats like me, who learnt their computer science almost fifty years ago.

And using the variable name "log" is still a break in style.
0
 
Julian HansenCommented:
And using the variable name "log" is still a break in style.
Perhaps but it came from the original code ...
0
 
Seven priceFull StackAuthor Commented:
Thanks guys, I thought I closed this question. I got everything working thanks to your guys first 2 solutions.
0
 
Julian HansenCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.