Change the value of a cell in a table dynamically with the use of Angular

I am currently developing a web application using Angular 6. Within the HTML template, I have included some code that showcases a specific part of an array within a table cell. It's worth noting that the table is constructed using div elements.

<div class='table_small'>
        <div class='table_cell'>Status</div>
        <div class='table_cell'>
          <p class="status" >{{incomingData.status}}</p>
        </div>
      </div>

One specific scenario that I am trying to address involves including a button within each table row that allows users to cancel a particular order. When the user clicks on this button, a pop-up or modal will prompt them for confirmation. If they select 'Yes', the status field value will temporarily change to "cancellation is in process" before being sent to the service. Once a successful response is received, the status will be updated to "cancelled".

I'm uncertain about the best way to implement this cancellation feature within the table cell. Any guidance or insights on how to achieve this would be greatly appreciated.

Thank you!

Answer №1

If you pass the element to a function and update its status, here's how it can be done:

<div class='table_small'>
    <div class='table_cell'>Status</div>
    <div class='table_cell'>
      <p class="status" >{{incomingData.status}}</p>
    </div>
    <div class='table_cell'>
      <button (click)="showCancelModal(incomingData)"> Cancel</p>
    </div>
  </div>

To implement this in the component, consider following this structure:

showCancelModal(incomingData) {
  // logic for displaying modal and obtaining user response
  if(response === 'yes') {
    incomingData.status = 'Cancellation in progress';
    yourService.cancel(incomingData)
    .pipe( finally(() => incomingData.status = 'Cancelled') )
     .subscribe();
  }
}

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

Keeping a sidebar's height consistent with a responsive square in Bootstrap 4

I have set up my design as follows: I've created a responsive image box that functions as a square using a pseudo element :after with the CSS property padding-bottom: 100%; The challenge I'm facing: I'm attempting to place a sidebar nex ...

How can one address the issue of undefined data within table cells?

I have encountered an issue while reading and displaying an XML file on a webpage using a JavaScript script. The problem arises when the page loads, and the information inside the cells of the table shows as "UNDEFINED". The intended display should include ...

Accessing Django static files is proving to be difficult

I recently set up a django project and attempted to integrate an HTML template. Unfortunately, I encountered an issue when trying to access files in the static folder. Below is my current configuration: #BASE_DIR = os.path.dirname(os.path.dirname(os.path ...

Ajaxed div disappears and reappears only after the div has finished loading

I ran into an issue with my jquery ajaxed site. The main content div is in the center with navigation on top. I needed to AJAX the content to prevent the flash video from restarting after each page load. My solution involved using the following code: $(do ...

Using conditional CSS in React/Next.js

While using Next.js, I have implemented conditional rendering on components successfully. However, I am facing an issue where the CSS styles differ between different components. Code 1: import React from "react"; import Profile from "../../ ...

Determining the position of p5.js input in relation to the canvas

Show me what you’ve got: function initialize() { var board = createCanvas(960,540); board.parent("drawingPad"); background('white'); var textbox = createInput(); textbox.position(10,10); textbox.parent("drawingPad"); } I’ve cre ...

create a function that automatically assigns colors to table fields based on their values

I have a table that dynamically displays a field with the id complaint_status, which can have values of "PENDING" or "CLEARED". I need help to set different background colors for the field based on these values: GREEN for CLEARED RED for PENDING Is the ...

An issue with Destination-Out Composition in HTML5 Canvas

While working on a canvas, I have encountered an issue with deleting a portion of a curve I have drawn. Specifically, I need to remove the last 25% of the curve after it is complete and keep only the first 75%. However, when attempting to delete the lines ...

Enhancing the appearance of a PHP HTML email

I scoured the web for an answer to this question and all I could find was to include the following: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; and ...

Tips for preventing menu flickering caused by overflow during CSS animations

I recently created a vertical menu with an interesting underline effect that appears when hovering over the menu items. Even though the snippet initially failed to execute, I discovered this cool hover effect (taken from here) which I wanted to implement: ...

How can you quickly check an element's visual properties following a CSS modification?

I am facing an issue where I want to modify the appearance of an element in an HTML page using CSS and then immediately check its visual properties. However, the changes specified in the CSS are not applied instantly, but rather after a delay. CSS: .node ...

Need help adding key:value pairs to a JavaScript dictionary? Here's how!

I am facing an issue with my JavaScript code. I have two HTML text input elements and a paragraph element. In my script, I have an empty JavaScript array and a function that is supposed to push the values of these two input elements as key-value pairs into ...

Step-by-step guide on utilizing jQuery to fade out all elements except the one that is selected

There are multiple li elements created in this way: echo '<ul>'; foreach ($test as $value){ echo '<li class="li_class">.$value['name'].</li>'; } echo '</ul>'; This code will generate the fol ...

Particular arrangement of a table

I am looking to create a responsive table that has a vertical left header row on mobile devices and a normal horizontal header row on desktop, like the following: Header 1 data data data Header 2 data data data Header 3 data data data Does anyone have ...

A comprehensive guide on connecting an HTML Label to a sqldatareader

Trying to associate a label with a datareader has been challenging. When dealing with an input type="text", I can easily accomplish something like this: NameLabel.Value = reader["Name"].ToString(); - <label id="lblName" runat="server"></label&g ...

How to efficiently center a jQuery Mobile Dialog on the screen using custom dimensions

I designed an app using jQuery Mobile and I'm looking to display a Dialog box when a button is clicked. The Dialog box should be centered on the screen with specified width and height. For reference, you can view the current version on jsfiddle. The ...

Assistance is required to navigate my character within the canvas

Having trouble getting the image to move in the canvas. Have tried multiple methods with no success. Please assist! var canvas = document.getElementById("mainCanvas"); canvas.width = document.body.clientWidth; canvas.height = document.body.clientHeight; ...

Submitting form by clicking a link on the page

To submit a POST request with "amount=1" without displaying it in the URL, I need the site to send this request when any link on the site is clicked. This JavaScript code achieves that with a GET request: window.onload = function () { document.body.oncli ...

Clear function of signature pad not working inside Bootstrap modal dialogue box

Currently, I'm working on implementing a signature pad dialogue box using Bootstrap modal. When the user clicks on the "Complete Activity" button, a dialog box should pop up with options for yes or no. If the user selects yes, another dialog box shoul ...

Switch the designation to Hover Class

I am working with nested divs and have assigned a CSS class to one of the inner divs. How can I trigger the hover effect of the class (class.hover) when the user hovers over the outer div, even if they are not directly over the inner div? I believe this m ...