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

change event

3 Answers 185 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Voss
Top achievements
Rank 1
Voss asked on 30 Nov 2011, 08:38 PM
Is leverage the "change" event the correct approach to wire up some templates and grid that use a common DataSource?

I have the following code, but it take about 5 seconds for the binding to occur even though the data is returned in under a second.

<script>

    $(document).ready(function () {
        var dsBoxScore = new kendo.data.DataSource(
            {
                type: "json",
                transport:
                {
                    read: "JsonBoxScoreGet"
                },

                change: function () {

                    var scriptTemplateBoxscoreHomeTeam = kendo.template($("#templateBoxScoreHomeTeam").html());
                    $("#scriptBoxScoreHomeTeam").html(scriptTemplateBoxscoreHomeTeam(this.data().HomeTeam));

                    var scriptTemplateBoxscoreAwayTeam = kendo.template($("#templateBoxScoreAwayTeam").html());
                    $("#scriptBoxScoreAwayTeam").html(scriptTemplateBoxscoreAwayTeam(this.data().AwayTeam));

                    $("#gridBoxScore").kendoGrid({
                        dataSource: this.data().HomeTeam.Players,
                        height: 350,
                        selectable: "row",
                        scrollable: true,
                        sortable: true,
                        pageable: false,
                        navigatable: true,
                        rowTemplate: kendo.template($("#rowTemplateBoxScorePlayerStats").html())

                    });

                },

                serverPaging: false,
                serverSorting: false

            });

        dsBoxScore.read();

    });
    </script>

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 01 Dec 2011, 09:50 AM
Hi Voss,

 Yes, the change event is the recommended way to consume a datasource. In your code you seem to initialize a new grid every time the change event is raised. Are you sure this is the desired result? You can just create a data source and the grid after that:

var dsBoxScore = new kendo.data.DataSource( { ... } )

$("#gridBoxScore").kendoGrid({
    dataSource: dsBoxScore
    ...
});

Regards,

Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Voss
Top achievements
Rank 1
answered on 01 Dec 2011, 01:28 PM
Not sure I know what you mean.

So how should I structure it then? You state that the change event is the recommended way to consume the datasource, but not the right place to init a grid. So not sure what to do.

I need to do the following and I'm not sure how to reference the datasource sub properties outside of the change event:

  $("#gridBoxScoreHomeTeam").kendoGrid({
                    dataSource: dsBoxScore.data().HomeTeam.Players,
                    height: 350,
                    selectable: "row",
                    scrollable: true,
                    sortable: true,
                    pageable: false,
                    navigatable: true,
                    rowTemplate: kendo.template($("#rowTemplateBoxScorePlayerStats").html())

                });
0
Atanas Korchev
Telerik team
answered on 01 Dec 2011, 02:04 PM
Hello Voss,

I guess we need more information about your scenario in order to help you further. Could you provide some more details? How much data are you binding the grid to? How do the templates look like? Ideally you could send a live url or a test project.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Data Source
Asked by
Voss
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Voss
Top achievements
Rank 1
Share this question
or