Enhancing AngularJs Kendo Grid Detail Template: Dynamically updating content based on selected row in the detail template

Experimenting with the KendoUI AngularJS Grid detail template has been quite insightful. I am currently facing an issue where I want to update a panel based on a row selected in the detail template grid.

Although I have successfully set up the onChange event to choose a value from the detail template grid, I am encountering difficulties in updating a variable on the $scope object. The value seems to remain unchanged, sticking to the default value.

What could be causing this inconsistency in updating the variable on the #scope object?

<div id="example">
<div ng-controller="MyCtrl">
    <kendo-grid options="mainGridOptions">
        <div k-detail-template>
            <kendo-tabstrip>
                <ul>
                    <li class="k-state-active">Orders</li>
                    <li>Contact information</li>
                </ul>
                <div>
                    <div kendo-grid k-options="detailGridOptions(dataItem)"></div>
                </div>
                <div>
                    <ul class="contact-info-form">
                        <li><label>Country:</label> <input class="k-textbox" ng-model="dataItem.Country" /></li>
                        <li><label>City:</label> <input class="k-textbox" ng-model="dataItem.City" /></li>
                        <li><label>Address:</label> {{dataItem.Address}}</li>
                        <li><label>Home phone:</label> {{dataItem.HomePhone}}</li>
                    </ul>
                </div>
            </kendo-tabstrip>
        </div>
    </kendo-grid>

    <div class="panel panel-default">
        <div class="panel-heading">Content</div>
        <div class="panel-body">
            {{content}}
        </div>
    </div>
</div>

<script>
angular.module("app", [ "kendo.directives" ])
    .controller("MyCtrl", function ($scope) {
        $scope.content = 'test';
        $scope.mainGridOptions = {
            dataSource: {
                type: "odata",
                transport: {
                    read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Employees"
                },
                pageSize: 5,
                serverPaging: true,
                serverSorting: true
            },
            sortable: true,
            selectable: true, 
            pageable: true,
            dataBound: function() {
                this.expandRow(this.tbody.find("tr.k-master-row").first());
            },
            columns: [{
                field: "FirstName",
                title: "First Name",
                width: "120px"
                },{
                field: "LastName",
                title: "Last Name",
                width: "120px"
                },{
                field: "Country",
                width: "120px"
                },{
                field: "City",
                width: "120px"
                },{
                field: "Title"
            }]
        };

        $scope.detailGridOptions = function(dataItem) {
            return {
                dataSource: {
                    type: "odata",
                    transport: {
                        read: "https://demos.telerik.com/kendo-ui/service/Northwind.svc/Orders"
                    },
                    schema: {
                        model: {
                            id: "OrderID"
                        }
                    },                        
                    serverPaging: true,
                    serverSorting: true,
                    serverFiltering: true,
                    pageSize: 5,
                    filter: { field: "EmployeeID", operator: "eq", value: dataItem.EmployeeID }
                },
                scrollable: false,
                sortable: true,
                selectable: true,
                change: onChange,
                pageable: true,
                columns: [
                { field: "OrderID", title:"ID", width: "56px" },
                { field: "ShipCountry", title:"Ship Country", width: "110px" },
                { field: "ShipAddress", title:"Ship Address" },
                { field: "ShipName", title: "Ship Name", width: "190px" }
                ]
            };                
        };
        function onChange(arg) {                
            console.log("The selected product id: [" + this.dataItem($(this.select()[0]).closest("tr")).id + "]");
            $scope.content = this.dataItem($(this.select()[0]).closest("tr")).id;
        }
    })

I have tested an inline Kendo provided onChange function like this:

<div kendo-grid k-options="detailGridOptions(dataItem)" k-on-change="handleChange(data, dataItem, columns)"></div>

It doesn't seem to work as intended due to the scope of data being the parent grid.

Answer №1

I successfully resolved the issue at hand.

The modification I made was changing selectable: true to selectable: "row". Additionally, I included k-on-change="handleChange(data) in both the child and parent grid, managing the change event with the function below on $scope:

 $scope.handleChange = function (data) {
            $scope.data = data;                
        };

This new approach is much more organized than my initial one and enables me to retrieve the OrderID as follows: {{data.OrderID}}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In JavaScript, the code fails to verify the email entered through a form

Hi, I'm not sure if this is the right place to ask my question but I'm having trouble with a code that I can't seem to figure out. I've tried various algorithms but none of them seem to work. My issue involves validating an email from a ...

Executed a function upon clicking when the component was mounted

When working with React JS, if you use list object mapping like this: const deleteUser = (email) => { alert(email); } const userList = users.map((user) => <li key={user._id}> {user.Name} {isAdmin ...

Is there a way to make a link open only on the second click, instead of the first?

Is it possible to have a popunder advert that opens only when the page is clicked a second time, not the first time? Here's the code for the popunder: <script type="text/javascript"> var uid = '35190'; var wid = '65325'; &l ...

Retrieve a live variable from an external JavaScript file

I'm currently working with an external file that showcases videos on my website using a unique URL with a token and expiration date. Here's an example: https://www.thevideositeurl.com/embed/231231/ To include this video on my page, I use the fo ...

Tips on capturing the response data in UI testing automation

Currently, I am working on automating a login page using WebDriverIO for UI Automation. After clicking the Login button, a request to *.com/user/login is triggered in the background. I need to capture this call's response in order to obtain a token r ...

What is the process for implementing token authentication within headers using an interceptor, especially when the token may be null?

In my Angular13 application with OAuth authentication, I am encountering issues when trying to add the token for all services. I have been unsuccessful in managing the undefined token. Despite trying various techniques to retrieve the token, I always enco ...

Using observables rather than promises with async/await

I have a function that returns a promise and utilizes the async/await feature within a loop. async getFilteredGuaranteesByPermissions(): Promise<GuaranteesMetaData[]> { const result = []; for (const guarantees of this.guaranteesMetaData) { ...

Is it possible to include multiple names in the package.json file and perform an npm installation by specifying one of those names?

My primary project incorporates various services such as frontend, backend, Algolia, notifications, etc. Each service has its own specific package.json file. I am looking to merge all the different package.json files into a single package.json file and re ...

Using a combination of ajax and php to enhance the voting system

Thank you for taking the time to read this. I am currently working on improving my skills, so I decided to embark on a project to enhance my knowledge. I have created a basic voting system where each content is displayed using PHP and includes an up or do ...

Changing a PHP object into an array

I've searched for solutions on various platforms, but my situation presents a unique challenge. In my PHP charts factory, I am passed an array of strings like: $charts = ['SomeChart', 'SomeOtherChart', 'AndAnotherChart' ...

Want to learn the process of closing a modal using Javascript?

I am working on implementing 6 different modals, each featuring an exit button named 'modal-box__exit-button'. I have attempted to use JavaScript to close the modals when the exit button is clicked, but it seems like my code may have some errors. ...

What is the best way to update an array within an object using Redux?

I am currently working on a code for redux that involves an array. const initialState = [{ id: '1', title: '', description: '' }]; My goal is to update the array to contain two objects like this: [{ id: '1', title: ...

Steps for identifying if the line before in a textarea is blank

Is there a way to identify the structure of individual lines within a textarea? As an example, consider the following contents in my textarea: this is the first line in textarea 1234 this is the second line starting with 1234 this is the fourth line and ...

What is the best method to access a MySQL database on my computer using a Node.js application without the need for SSH?

I have a mysql server setup on my ec2 instance. I'm trying to connect to this database from my Node.js app running locally using the code snippet below: const mysql = require('mysql2/promise'); const mysqlHost = config.host; const mysqlUser ...

Using JQuery to fill an HTML dropdown menu with data from a JSON file

I've been struggling with this issue for a while and despite reading through other posts, I still can't seem to get it to work. My problem lies in populating a drop down menu with JSON data. Although the drop down menu appears on my HTML page, i ...

Mastering the art of managing unchecked and checked checkboxes in Angular 2: A comprehensive guide

I have a code snippet where I want to display the initial state of checkboxes based on the 'initialstatus' array in the UI. I should be able to randomly change the status of any checkbox on the UI, and that change should also be reflected in the ...

Attempt to generate a function in JavaScript that mirrors an existing one

How can I create a javascript function similar to loadAllOriginal, but with the value of the variable allEmployees being a list of employee objects (ID, FirstName, LastName)? I am attempting to implement this method in combination with autocomplete from ...

The display and concealment of a div will shift positions based on the sequence in which its associated buttons are clicked

I am in need of assistance with coding (I am still learning, so please excuse any syntax errors). What I am trying to achieve is having two buttons (button A and button B) that can toggle the visibility of their respective divs (div A and div B), which sh ...

Guide on establishing a connection with a TCP server and sending a JavaScript script to it

I am completely new to JS and node. I am using SkyX Pro, a telescope management software that has the capability to run a TCP Server on port 3040. By connecting with Netcat and providing it with Javascript starting with //* Javascript *//, I can control ca ...

How to access iFrame in ReactJS using document.getElementById

I am facing a challenge on my website where I need to transfer data (using postMessage) to an iframe. Typically in plain JavaScript, I would use techniques like document.getElementById or $("#iframe") in jQuery to target the iframe. However, I am unsure ...