possible kendo.rednder() problem?

3 posts, 0 answers
  1. DocG
    DocG avatar
    6 posts
    Member since:
    Dec 2011

    Posted 15 Dec 2011 Link to this post

    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. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 15 Dec 2011 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. DocG
    DocG avatar
    6 posts
    Member since:
    Dec 2011

    Posted 16 Dec 2011 Link to this post

    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!
Back to Top