javascriptkendo-uikendo-gridkendo-asp.net-mvc

Multidimensional dataSource fit to kendo grid


I have a multi dimensional datasource with a dynamic column like this:

{
TaskName: "Sample",
Oct12018: {
    Assigned: 2,
    Completed: 0
},
Oct22018: {
   Assigned: 2,
   Completed: 2
},
... and so on.

this is how I create that data: I dynamically create a column for the date.

$.each(groupedData, function (col, val) {
                if (property != 'DateFormat' && property != 'Date') {
                    schedule[i] = {};
                    
                }
                for (var j = 0; j < val.length; j += 1) {
                    var currentItem = val[j]
                    var property = Object.keys(currentItem)[i];
                    schedule[i]["TaskDescription"] = currentItem.TaskDescription;
                    //schedule[i][currentItem.DateFormat] = currentItem["Assigned"];
                    for (var x = 0; x <= 2; x++) {
                        schedule[i][currentItem.DateFormat] = {};
                        schedule[i][currentItem.DateFormat]["Assigned"] = currentItem["Assigned"];
                        schedule[i][currentItem.DateFormat]["Completed"] = currentItem["Completed"];
                        //schedule[i]["Completed"] = currentItem["Completed"];
                    }
                }
                i += 1;
            });

Now I wonder how can I put this on my kendo grid.


Solution

  • Thanks for your answers, i was able to fit my grid with my dynamic column.

    function generateColumns(sampleDataItem) {
            var columnNames = Object.keys(sampleDataItem[0]);
            return columnNames.map(function (name) {
                    return {
                        field: name,
                        width: 200,
                        title: name,
            }}