Rejuvenate Kendo Details With AngularJS Directives

I'm currently dealing with a grid which automatically sets up a data source and loads a sub-grid for each item. This makes the markup fairly easy to work with.

<div class="thegrid"
     kendo-grid
     k-data-source="vm.GeneralData"
     k-options="vm.gridMainOptions">
    <div k-detail-template>
        <div kendo-grid k-options="vm.detailGridOptions(dataItem)"></div>
    </div>
</div>

Within the detail template of the sub grid, there's a column that triggers an event when an ng-click is detected.

columns: [
{
    field: "Id",
    editable: false,
    hidden: true
},
{
    title: "",
    width: "160px",
    editable: false,
    template:
    "<span class='glyphicon glyphicon-remove remove-template'  
           ng-click='vm.removeItem(dataItem)'></span><",
    attributes: {
    "class": "managing-templates-column",
    "title": "Delete This Template"
}

]

Inside the controller, there's a method set up to handle this event.

function removeItem(dataItem) {

    console.log("remove", dataItem);
    //removed code that makes an ajax call to actually delete item

    //... and now need to refesh that datasource that this belongs to.

}

I'm trying to figure out how to access the dataItem's data source in order to refresh it. Any suggestions?

Answer №1

When using Kendo's template engine, you have access to the data object, which essentially represents your dataItem. Here is how you can utilize it:

"<span class='glyphicon glyphicon-remove remove-template' ng-click='vm.removeItem(data)'></span>"

If this approach doesn't work for you, consider accessing the dataItem directly through the DOM:

"<span class='glyphicon glyphicon-remove remove-template' ng-click='vm.removeItem(this)'></span>"

Here is a sample function to assist with removing the item:

function removeItem(span) {
    var $tr = $(span).closest("tr"),
        grid = $tr.closest(".k-grid").data("kendoGrid"),
        dataItem = grid.dataItem($tr);
}

UPDATE

Referencing this answer, you might try the following approach:

"<span class='glyphicon glyphicon-remove remove-template' ng-click='vm.removeItem($event)'></span>"

And within the updated function:

function removeItem($event) {
    var $tr = $($event.currentTarget).closest("tr"),
        grid = $tr.closest(".k-grid").data("kendoGrid"),
        dataItem = grid.dataItem($tr);
}

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

Tips for halting a MySQL database transaction within a NodeJS environment using expressJS

Recently, I encountered a coding challenge that involved managing a long database transaction initiated by a user. The scenario was such that the user inadvertently updated 20 million entries instead of the intended 2 million, causing a significant impact ...

When attempting to showcase an MUI icon that was imported, I encounter the following issues: Invalid hook call and the <ForwardRef(SvgIcon)> component

Encountering issues while trying to display an imported MUI icon leads to the following errors: Error: https://i.stack.imgur.com/USdEx.png Sample Code: import React from 'react' import ThreeDRotation from '@mui/icons-material/ThreeDRotati ...

Synchronous Http calls in AngularJS Promise Handling

I'm experiencing an issue with the then function not getting called in one of my controllers when making multiple synchronous http calls. In the code snippet below, the console.log(data) statement in my controller is not being triggered as the flow d ...

Using React components to create an anchor element for a popover display

Hey, I'm just starting out with React and trying to wrap my head around Hooks like useState. It's a bit challenging for me, and I want to keep things simple without making them too complex. I've encountered an issue when transitioning a Rea ...

Change the ISO date format into a date format that includes the name of the month and

Could someone please help me with a simple task using only JavaScript? I have a date in the format 2021-05-06 and I need to convert it to Fri 7 May. Any suggestions on how to accomplish this? Thanks! ...

Enclose the serialized JSON string in single quotes to avoid parsing errors caused by using double quotes

My current task involves utilizing the JSON.stringfy() and JSON.parse() methods to serialize and deserialize JSON data. Everything is functioning properly when working with a single quoted serialized string. However, I am encountering an issue when attempt ...

Unable to load JavaScript in an HTML file

I have tried numerous solutions for my issue, but none seem to work. When testing in JSFiddle, the code works perfectly due to automatic onload support. However, when I open the same HTML file locally in Chrome/IE/FireFox, the layout is correct but the J ...

Altering CSS attribute values using a random number generator

Is there a way to randomly change the animation-duration attribute in the following CSS code? I want it to range from 0 to 1. @keyframes blink { 50% { border-color: #ff0000; } } p{ animation-name: blink ; animation-duration: 0.1s ; animatio ...

Managing promise errors by verifying the response

I am currently facing an issue where I need to handle inappropriate responses in the 'then' block of the code snippet below. getData().then(response => transformData(response)); I believe I need to implement something like this, but I am uns ...

Avoid triggering a second event: click versus changing the URL hash

One of the pages on my website has tabs that load dynamic content: HTML <ul> <li><a href="#tab-1">TAB 1</li> <li><a href="#tab-2">TAB 2</li> <li><a href="#tab-3">TAB 3</li> </ul&g ...

Angular 1: Handling Multiple Conditions and Exclusions Based on Other Conditions

I have currently added an additional span to accommodate one condition. <div ng-repeat="(key, resultLinks) in resultGroup.resultLinks"> <div ng-if="key < 4 || viewMore" ng-repeat="(subKey, linksWrap) in resultLinks.linksWrap"> & ...

There are currently no articles found that match the search query

Recently, I started working with Django, but I am facing an issue with slug. Whenever I send a request to the Slug, I encounter an error. The error message I receive is: Articles matching query does not exist. Furthermore, I am facing another error while ...

How to Modify the Data in a Dynamic Object within the Vuex Store in a Nuxt Application

Within my Vue/Nuxt project, I have implemented a form where users can add and update dynamic fields for calculating price offers. Upon loading the form, one field is created using the beforeMount lifecycle, with the option for users to add more fields as n ...

Utilizing Vue.js for Streamlined Form Management: Adding and Editing with One Form

I'm attempting to utilize the same component for both adding and editing functionality in my application. Utilizing Firebase, I am checking if there is an id in the route parameters. If there is, it should render as the edit form; otherwise, it should ...

Updating a specific array element in MongoDB by its id

I've been attempting this task since yesterday without success. I have two distinct Schemas - the User Schema and the Vital Signs Schema. The Vital Signs Schema is nested inside the User Schema as an array. My goal is to modify a specific vitalSigns ...

Using javascript, add text to the beginning of a form before it is submitted

I'm trying to modify a form so that "https://" is added to the beginning of the input when it's submitted, without actually showing it in the text box. Here's the script I have so far: <script> function formSubmit(){ var x ...

Looking to create a clone of an HTML element, make some modifications, and extract the HTML string without impacting the DOM?

After working with some HTML code, I encountered the following: <div style="background:red;width:900px;height:200px" id="wrap"> <div id="inner" style="width:300px;float:left"> ... </div> </div> The tasks at hand are ...

Google Cloud Platform (GCP) reported a Stripe webhook error stating that no matching signatures were found for the expected signature

Current Stripe version: "8.107.0" I am encountering an issue with Stripe webhook verification whenever I deploy my webhook on Google Cloud Platform (GCP). Despite trying various methods to include the raw body in the signature, including the cod ...

Building a listview using Angular, MySQL, and Node.js

As a newcomer to Angular, I've been navigating my way through the learning process with some success but also encountering challenges. Although I've managed to resolve certain issues within the application, such as successfully inserting data int ...

Using setTimeout within a ForEach loop does not adhere to the specified milliseconds for waiting

Although ForEach console.log's very fast, I am looking to introduce a delay of 8 seconds before logging the next item in Set. I experimented with setTimeout but it doesn't appear to output at the precise milliseconds specified. const completedIds ...