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

possible kendo.rednder() problem?

2 Answers 98 Views
Templates
This is a migrated thread and some comments may be shown as answers.
DocG
Top achievements
Rank 1
DocG asked on 15 Dec 2011, 04:06 PM
Hello,

It seems i might have ecnountered a possible problem with kendo.render() (the method suggested in "Batch CRUD Operations With Kendo UI DataSource" blog post for updating templates). I have several templates displaying the same data in different ways. In the DataSource, I defined a change method to update all the templates when the data is changes. The DataSource looked something like this:

folderListData = new kendo.data.DataSource({
    data: folderList,
    schema: { model:folderModel },
    change: function() {
        for (var i = 0; i < templates.length; i++) {
             $(parents[i]).html(kendo.render(templates[i], this.view()));
        }
    }
});

So the change loops through the templates, and each template has a parent element where its supposed to be inserted too. But it didn't work. When the change ran, all the content defined in the templates simply disappeared (the parent elemets' content was repalced with nothing).
Altough when I rewrote it like this, it worked perfectly:

folderListData = new kendo.data.DataSource({
    data: folderList,
    schema: { model:folderModel },
    change: function() {
        var data = this.view();
        for (var i = 0; i < templates.length; i++) {
            $(parents[i]).html(templates[i](data));
        }
    }
});

So instead of the render(), i use the template function directly, and hand the data to it.
What could the problem be? Whats the real difference between the two?

(The framework is awesome by the way! Thank you!)

Regards,
Greg

2 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 15 Dec 2011, 05:52 PM
Hi Docg,

 I think that the problem may be that you iterate the data by yourself in your templates - something, which kendo.render does in order to simplify datasource binding. To best explain the render, I am providing its source code (quite simple, actually):

render: function(template, data) {
    var idx,
        length,
        html = "";
 
    for (idx = 0, length = data.length; idx < length; idx++) {
        html += template(data[idx]);
    }
 
    return html;
},
 

Best wishes,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
DocG
Top achievements
Rank 1
answered on 16 Dec 2011, 10:29 AM
Ah, I see, so render() iterates my data by itself! Yes, there was an iteration on data in the template, this explains it! Thank You!
Tags
Templates
Asked by
DocG
Top achievements
Rank 1
Answers by
Petyo
Telerik team
DocG
Top achievements
Rank 1
Share this question
or