Solved

kendo spreadsheet data return

Posted on 2016-07-22
15
88 Views
Last Modified: 2016-07-26
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

0
Comment
Question by:sevensnake77
  • 7
  • 4
  • 4
15 Comments
 
LVL 27

Assisted Solution

by:BigRat
BigRat earned 250 total points
ID: 41725818
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
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41725844
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
 
LVL 9

Author Comment

by:sevensnake77
ID: 41728396
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Author Comment

by:sevensnake77
ID: 41728476
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
 
LVL 9

Author Comment

by:sevensnake77
ID: 41728709
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
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41728805
Please post your code. The code I posted earlier does not create one long array.
0
 
LVL 27

Expert Comment

by:BigRat
ID: 41729257
Just as a matter of interest, Julian, what is "this" in line 19 of your code?

http://justjs.com/posts/this-considered-harmful
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41729303
@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
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41729304
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
 
LVL 27

Expert Comment

by:BigRat
ID: 41729345
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
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 41729371
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
 
LVL 27

Expert Comment

by:BigRat
ID: 41729375
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
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41729444
And using the variable name "log" is still a break in style.
Perhaps but it came from the original code ...
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 41730438
Thanks guys, I thought I closed this question. I got everything working thanks to your guys first 2 solutions.
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41730632
You are welcome.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
To array or not to array 11 55
jQuery delay animation 3 29
insert a falling animation of heart  in php 4 23
Excel 2010:  Creating a "Yes" or "No" Pop-Up 20 39
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Zack
Viewers will learn about various customizable options in Excel 2013.
Viewers will learn how to share Excel data with others from desktop Excel, as well as Excel Online via OneDrive, and embed an Excel file on a website.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question