0
votes

I have created a kendo grid for 10 number of products in my project. I want the kendo window containing the details of the product to popup when I click on the productname displayed in the kendo grid.

I have looked into the demos of the kendo grid but I don't want the details of the product selected to be edited and also I don't want to use a separate column for details button as shown in the examples and demo.

I also looked into the music store demo of kendo ui but I couldn't understand its code as its in jQuery and I am using asp.net mvc with razor syntax for my project

Note: I want window to appear only when I click on the name of the product and display its details.

2

2 Answers

0
votes

You can use:

$('#grid').on("click", "tr.k-state-selected", function (e) {
    // open window here
    // you have i.e. Id here $('#grid').dataItem($('#grid').select()).Id
});

For this you must set option selectable: "row" in grid configuration. Otherwise you can use just:

$('#grid').on("click", "tr", function (e) { ... }
0
votes

You can make use of the detailTemplate for achieving it.

 <script>
            var wnd,
                detailsTemplate;

            $(document).ready(function () {
                var grid = $("#grid").kendoGrid({
                    dataSource: {
                       pageSize: 20,
                       data: createRandomData(50)
                    },
                    pageable: true,
                    height: 550,
                    columns: [
                        { field: "FirstName", title: "First Name", width: "140px" },
                        { field: "LastName", title: "Last Name", width: "140px" },
                        { field: "Title" },
                        { command: { text: "View Details", click: showDetails }, title: " ", width: "180px" }]
                }).data("kendoGrid");

                wnd = $("#details")
                    .kendoWindow({
                        title: "Customer Details",
                        modal: true,
                        visible: false,
                        resizable: false,
                        width: 300
                    }).data("kendoWindow");

                detailsTemplate = kendo.template($("#template").html());
            });

            function showDetails(e) {
                e.preventDefault();

                var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
                wnd.content(detailsTemplate(dataItem));
                wnd.center().open();
            }
        </script>

        <script type="text/x-kendo-template" id="template">
            <div id="details-container">
                <h2>#= FirstName # #= LastName #</h2>
                <em>#= Title #</em>
                <dl>
                    <dt>City: #= City #</dt>
                    <dt>Birth Date: #= kendo.toString(BirthDate, "MM/dd/yyyy") #</dt>
                </dl>
            </div>
        </script>

Go to this fiddle for a working demo

[UPDATE] Here's the code snippet for showing the window while clicking on the Product Name

 <script>
            var wnd,
                detailsTemplate;

            $(document).ready(function () {
                var grid = $("#grid").kendoGrid({
                    dataSource: {
                       pageSize: 20,
                       data: createRandomData(50)
                    },
                    pageable: true,
                    height: 550,
                    columns: [
                        { field: "FirstName", title: "First Name", width: "140px",attributes: { "class": "FirstName"} },
                        { field: "LastName", title: "Last Name", width: "140px" },
                        { field: "Title" }]
                }).data("kendoGrid");

                wnd = $("#details")
                    .kendoWindow({
                        title: "Customer Details",
                        modal: true,
                        visible: false,
                        resizable: false,
                        width: 300
                    }).data("kendoWindow");

                detailsTemplate = kendo.template($("#template").html());

                $('#grid').on("click", ".FirstName", function (e) {

                  e.preventDefault();

                var dataItem =               $("#grid").getKendoGrid().dataItem($(e.currentTarget).closest("tr"));
                wnd.content(detailsTemplate(dataItem));
                wnd.center().open();


  });
            });


        </script>

        <script type="text/x-kendo-template" id="template">
            <div id="details-container">
                <h2>#= FirstName # #= LastName #</h2>
                <em>#= Title #</em>
                <dl>
                    <dt>City: #= City #</dt>
                    <dt>Birth Date: #= kendo.toString(BirthDate, "MM/dd/yyyy") #</dt>
                </dl>
            </div>
        </script>

Working demo is here