This is a migrated thread and some comments may be shown as answers.

Using type:"Array" in model for pivotDataSource

2 Answers 156 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 08 Sep 2015, 01:44 PM

Imagine that we have table with some data ( attached file: img1.png )
Using this data I created pivotDataSource for my Kendo pivotGrid like this:demo
As we can see our data looks like:

var someData = [
          {
            Question1:'Q1Answr1',
            Question2:'Q2Answr1',
            Question3:'Q3Answr1',
            Question4: 1
          },
  
          {
            Question1:'Q1Answr2',
            Question2:'Q2Answer2',
            Question3:'Q3Answer2',
            Question4: 1
          },
  
  
          {
            Question1:'Q1Answr3',
            Question2:'Q2Answer3',
            Question3:'Q3Answer3',
            Question4: 1
          },
        ];

For each question property we use only one answer, and our model looks like:

model: {
                       fields: {
                           Question1: { type: "string" },
                           Question2: { type: "string" },
                           Question3: { type: "string" },
                           Question4: {type: "number"}
                       }
                   },
                ...

But if I want to use table with data wich will look like: ( attached file: img2.png )
I must separate this data in this way: (find all possible combinations for answers): ( attached file: img3.png )

And only after that I can create someData js obj as we saw above.

var someData = [
          {
            Question1:'Q1Answr1.1',
            Question2:'Q2Answr1.1',
            Question4: 1
          },

 

for our pivotGrid.
The problem is, that we can have many questions ( 100+ questions) and for each question we can have ( 1-5+ answers) , so if I'll have in my row 5 answers for each question I must create (5*100)! unique combinations of answers, and after that i can create data for my pivotGrid where each data item will have one answer for one question.
Why I must do that ?
According to documentation Kendo dose not allow us to use Array type in model, so we cant write like this:

 

fields: {
      Question1: { type: "Array" },

 

So my questions are: 1) Does kendo have mechanism which allow me use array in my model. For example i will give it data wich will looks like:

var someData = [
          {
            Question1:['Q1Answr1.1','Q1Answr1.2'],
            Question2:['Q2Answr1.1','Q1Answr2.2','Q2Answr2.3'],
            Question4: 1
          },

and it will build me pivot grid like this: ( attached file: img4.png )
but not like this ( attached file: img5.png )

2.Maybe you can advise me another solution to solve this problem with data separation. For example can we create a pivot grid configurator UI where we can choose only two items (two questions) (one for column , one for row), and after that , we will calculate all possible combinations of theirs answers , and after that we can use this data for our pivot grid.In other words: can we initialize our kendo pivot grid and kendo pivot grid configurator using one dataSource after that detect wich data was dropped in columns and rows after that make some calculations and prepare another dataSource ( using this dropped data) and replace old dataSource using new dataSource .Maybe you can advise me another solution to solve this problem with data separation.Thank you.

2 Answers, 1 is accepted

Sort by
0
Steve
Top achievements
Rank 1
answered on 08 Sep 2015, 01:45 PM
0
Georgi Krustev
Telerik team
answered on 10 Sep 2015, 08:59 AM
Hi Steve,

I answered the support thread opened on the same subject. I would suggest you keep the discussion in only on thread in order to avoid duplication. Thank you for the understanding.

Here is a quote of the answer:

In general, the PivotDataSource client cube works with flat data, where every data item contains primitive value (string, number and etc). The data source does not support binding to data items  which fields contains arrays with specific values. In other works, the client cube is not designed to generate tuples (cartesian product) from array fields. That being said, you will need to expand the source with arrays into data items with primitive values, like you did in the test demo.

With regards to the second questions, I suppose that you would like to use the PivotConfigurator to create a specific dimensions setup and then use only that subset as data for the grid. In general, the PivotDataSource does exactly this. It uses the flat data to create only a subset (cube slice) based on the given configuration. Note that the whole data should be provided initially.

If you would like to update source between dimensions drop, then it will not be possible.

To recap
  • the "compressed" way you keep the data is not understandable to PivotDataSource and you will need to expand the data into data items with primitive values.
  • changing the source between dimensions setup is not supported and in general will not be efficient approach at all.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
PivotGrid
Asked by
Steve
Top achievements
Rank 1
Answers by
Steve
Top achievements
Rank 1
Georgi Krustev
Telerik team
Share this question
or