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

Display DataSource data on Grid Rows (not columns)

2 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Larissa
Top achievements
Rank 1
Larissa asked on 24 Feb 2016, 06:38 PM

There is a way to display the dataSource as rows and not columns?

My dataSource has only one record with 30 properties. I would like to display the properties as rows (property1 => row1, property2 => row2, ...) instead of columns (property1 => column1, property2 => column2, ....).

In fact, I would like to retrieve 3 records (each one with 30 properties), but the 3 records would be the colums and the common 30 properties would be the rows.

How can I do that?

2 Answers, 1 is accepted

Sort by
0
Larissa
Top achievements
Rank 1
answered on 25 Feb 2016, 11:01 AM

This is what I did so far, but I'm not sure this is the right way.

 

var _dataSource = function () {
 
        var dataSource = new kendo.data.DataSource({
            transport: {
                read: { // returns only 3 records
                    url: url,
                    dataType: "json"
                }
            },
            schema : {
                data: "data",
                total: "total",
                parse: function (data) {
 
                    console.log(data);
                    var dataArray = [];
                    var i = 0;
                    for (var property in data[0]) {
 
                        console.log(property);
                        console.log(data[0][property]);
 
                        var record = {
                            header: "",
                            headerId: "",
                            record1: "",
                            record2: "",
                            record3: ""
                        };
 
                        record.header = headerRows[i]; // array of header string (the 30 properties)
                        record.headerId = property;
                        record.record1 = data[0][property];
                        record.record2 = data[1][property];
                        record.record3 = data[2][property];
 
                        console.log(record);
 
 
                        dataArray.push(record);
                        i++;
                    }
                    return dataArray;
                }
            }
        });
 
        return dataSource;
    };

But this gives the error: TypeError: e is undefined

0
Larissa
Top achievements
Rank 1
answered on 25 Feb 2016, 12:50 PM
Got it! So simple!
Instead of build the logic on schema, I did it on data.
Actually, it makes more sense on data. Don't know why I was trying on schema.
Tags
Grid
Asked by
Larissa
Top achievements
Rank 1
Answers by
Larissa
Top achievements
Rank 1
Share this question
or