Question

I have to put a kendochart and a kendo grid on page which are bound with different data sources i.e. table from sql database. I need to update kendogrid on click of kendochart for different part. suppose kendochart displays 5 part for users A, B, C, D, E, F then click on any part say B will update kendo grid for user B. Please suggest how this functionality can be achieved in html.

Was it helpful?

Solution

Please try with the below code snippet.

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
    <link href="http://cdn.kendostatic.com/2014.1.318/styles/kendo.common.min.css" rel="stylesheet" />
    <link href="http://cdn.kendostatic.com/2014.1.318/styles/kendo.default.min.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://cdn.kendostatic.com/2014.1.318/js/kendo.all.min.js"></script>
    <script type="text/javascript">
        var data = [
            {
                "source": "Hydro",
                "percentage": 22
            },
            {
                "source": "Solar",
                "percentage": 2
            },
            {
                "source": "Nuclear",
                "percentage": 49
            },
            {
                "source": "Wind",
                "percentage": 27
            }
        ];

        var gridData = null;

        $(document).ready(function () {
            $("#chart").kendoChart({
                title: {
                    text: "Break-up of Spain Electricity Production for 2008"
                },
                legend: {
                    position: "bottom"
                },
                dataSource: {
                    data: data
                },
                series: [{
                    type: "pie",
                    field: "percentage",
                    categoryField: "source",
                    explodeField: "explode"
                }],
                seriesColors: ["#42a7ff", "#666666", "#999999", "#cccccc"],
                tooltip: {
                    visible: true,
                    template: "${ category } - ${ value }%"
                },
                seriesClick: function (e) {
                    gridData = getDummyData(e.category);
                    bindGrid();
                }
            });
        });

        function getDummyData(catval) {
            var dataG = [
            {
                "ID": 1,
                "Name": catval
            },
            {
                "ID": 2,
                "Name": catval
            }
        ];

            return dataG
        }

        function bindGrid() {
            $("#grid").kendoGrid({
                dataSource: {
                    data: gridData,
                    schema: {
                        model: {
                            fields: {
                                ID: { type: "number" },
                                Name: { type: "string" }
                            }
                        }
                    },
                    pageSize: 1
                },
                height: 430,
                scrollable: true,
                sortable: true,
                filterable: true,
                pageable: {
                    input: true,
                    numeric: false
                },
                columns: [
                            "ID",
                            { field: "Name" }
                        ]
            });
        }
    </script>
</head>
<body>
    <div>
        <div id="chart">
        </div>
        <div id="grid">
        </div>
    </div>
</body>
</html>

DEMO

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top