0
votes

I have a list of dynamically generated columns in Kendo grid. I am using here colsList just as an example.

var colsList = ["A", "B", "C"];

    for (var j = 0; j < colsList.length; j++){

    var columnSchema = {
                            "field": colsList [j],
                             template: function (dataItem) {
                                 return getTemplate(dataItem, colsList [j]);
                             }
                        };
    }

    var getTemplate = function (dataItem, field) {
            // return tempate format;
        };

When getTemplate is called, second parameter i.e. field is always passed here as the last item of colsList. I need to prepare a column template which will information about the column field associated with it. How can this be achieved ? Have tried to do this via a number of ways but have not been successful.

I am new to kendo.js and not much familiar with templates.

Is there any other way of preparing template which will help me in achieving what i want to. dataItem and associated col field are the main two requirements while preparing template as on refreshing grid datasource, some conditions need to be checked in template and column data will be filled accordingly.

1

1 Answers

0
votes

I have finally found out the way to get the column field by using each function of jQuery instead of using for loop as follows:

var colsList = ["A", "B", "C"];

$.each(colsList, function (index, item) {

    var columnSchema = {
                            "field": item,
                             template: function (dataItem) {
                                 return getTemplate(dataItem, item);
                             }
                        };
    });

    var getTemplate = function (dataItem, item) {
    /* item gives the column field for which template will be set*/
            // return tempate format;
        };

But still I have no idea why it behaves differently in case of for loop and returns field as undefined in template.