Edit data within an Angular table on-the-fly

Currently, I am in the process of developing a dynamic table that may have an unknown number of columns and rows. My goal is to incorporate inline editing with inline templates using ng-include.

The first issue at hand:

I am faced with the challenge of utilizing ng-include at the < tr > level while including scripts within < td > elements. Is this even achievable? Although calling ng-include at the < td > level is an option, it may lead to significant overhead...

The second challenge:

How can I utilize the same ng-include to include edit_btn/display_btn templates outside of ng-repeat as the final cells?

        <tr ng-repeat="row in model.array" ng-include="model.isEditMode(row)">
            <td ng-repeat="(k, v) in row" ng-show="model.header[$index].display == true" class="text-center" >
                <script type="text/ng-template" id="edit">
                    <div ng-if="model.header[$index].isDisabled == true">
                        <div ng-if="model.header[$index].type == 'datetime'">
                            <input type="text" class="form-control" ng-model="model.dateTime"/>
                        </div>
                        <div ng-if="model.header[$index].type == 'string'">
                            <input type="text" class="form-control" ng-model="v"/>
                        </div>
                    </div>
                    <div ng-if="model.header[$index].isDisabled == false">
                        <div ng-if="model.header[$index].type == 'datetime'">
                            <input type="text" class="form-control" ng-model="model.dateTime" />
                        </div>
                        <div ng-if="model.header[$index].type == 'string'">
                            <input type="text" class="form-control" ng-model="v" />
                        </div>
                    </div>
                </script>
                <script type="text/ng-template" id="display">
                    <div ng-if="model.header[$index].isDisabled == true">
                        <div ng-if="model.header[$index].type == 'datetime'">
                            {{model.dateTime}}
                        </div>
                        <div ng-if="model.header[$index].type == 'string'">
                            {{v}}
                        </div>
                    </div>
                    <div ng-if="model.header[$index].isDisabled == false">
                        <div ng-if="model.header[$index].type == 'datetime'">
                            {{model.dateTime}}
                        </div>
                        <div ng-if="model.header[$index].type == 'string'">
                            {{v}}
                        </div>
                    </div>
                </script>
            </td>
            <script type="text/ng-template" id="edit_btn">
                <td>
                    <button type="button" class="btn btn-primary" ng-click="model.save(entry)">save</button>
                </td>
            </script>
            <script type="text/ng-template" id="display_btn">
                <td>
                    <button type="button" class="btn btn-primary" ng-click="model.edit(entry)">edit</button>
                </td>
            </script>
        </tr>

Answer №1

If you're looking to incorporate editable fields in Angular, check out Angular-xeditable. Navigate to this link for more information: . It has everything you need for easy implementation.

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

Ways to modify the pre-defined value in a TextField

I encountered a situation where I have a form with pre-filled data from a specific country. The data is initially read-only, but the user can click on the edit button if they wish to make changes. The issue arises when trying to edit the value in the Text ...

What techniques can I use to generate a 3D visual effect by shifting the background image layer as the user scrolls (creating a Parallax effect

I have combined two images in the heading; one on top of the other. My goal is to create a subtle vertical movement in the background image as the user scrolls, giving the illusion of depth. Both images share the same width, but the background image is tal ...

Modify the appearance of a specific <td> element using JavaScript to change its color

I am working on creating a quiz using HTML, displayed in a table format. Upon verification, I want to highlight the correct choice (which is represented by a <td> tag) in green, and the incorrect choice in red using the background property. Is there ...

What is the proper way to transfer data from a file using npm's request package?

I'm currently utilizing npm's request module to interact with an API. The API specifications require that data be sent through a file using the @site.json notation when making a CURL request. For example: curl -X POST -d @site.json 'https ...

What is the best approach to managing an Angular promise within the controller utilizing TypeScript?

My Service is responsible for making a data request: /// <reference path="../../typings/reference.ts" /> module app { 'use strict'; export class VehicleMakeService { static $inject = ['$http']; constructor(private $htt ...

Having trouble downloading the compression webpack plugin using npm, as it keeps throwing an error

Hey there, this message pops up when attempting to execute the following command: npm install compression-webpack-plugin Here is the accompanying error: `PS D:\phaser games\game-slot-machine> npm install compression-webpack-plugin npm ERR! ...

Convergence phenomenon in SVG when two distinct paths intersect

Working with individual SVG paths and in need of a mitre effect when there is a path join, which is a new concept for me. The SVG shape resembles a polygon, with each side as its own individual path. Although the sample SVG code provided does not display ...

Server has sent an Ajax response which needs to be inserted into a div

I have a modal window that sends a POST request to the server. Before returning to the view, I store some information in ViewData. Here's an example of what I'm doing: ViewData["Msg"] = "<div id=\"msgResponse\" class=\"success ...

Having trouble with the speed of multiple jQuery posts?

We have encountered some challenges with calling multiple jQuery posts since switching to our new server. On certain pages, we are making multiple jQuery post requests as shown below: $.ajax({ type: "POST", url: "../files/processed/includes/proce ...

Angular's routeProvider is only able to detect routes specified with #/foo, rather than #!/foo. It prefers the hash symbol over

My application is functioning properly with routes like: when('/people/new', { templateUrl: 'partials/person-detail.html', controller: 'PersonDetailCtrl' }). when('/people/:id', { templateUrl: 'partials/person- ...

What is the best way to validate the body object when working with Actions2 in sails.js?

Just starting out with sails.js I understand that the inputs object allows actions2 to validate the request parameters. However, how can I access and validate the request body? For example, req.body. I know I can access this from this.req.body, but I was ...

Is the security of Angular's REST authentication reliable?

My goal is to establish a secure connection with a REST service using Angular. I have come across the official method, which involves setting the authentication ticket like this: $httpProvider.defaults.headers.common['Authorization'] = 'dhf ...

Error: The callback specified is not a valid function

Here is a function example: reportAdminActions.reportMemberList(project, function(data) { console.log(data); }); This particular function gets called by another ajax operation, similar to the one shown below: reportMemberList: function(projectId, ca ...

What is the most effective method for destructuring within React components?

Observing how people implement destructuring in functional components in React, I have noticed a common pattern. const InputGroup = ({ name, placeholder, value }) => ( However, my preferred method differs: const InputGroup = props => { ...

Adjust the HTML 5 range slider to update according to the selected value

Is it possible to create a custom marker on an HTML5 range input element? I'm looking for a way to change the design of the circle marker as it moves along the scale from 1 to 10. Specifically, I want to change the color of the marker based on its po ...

Converting MultiSelect Array from JavaScript to MySQL

I recently implemented a multiselect feature on the client side: <select name="country" data-placeholder="Choose a Country..." tabindex="2"> <option name="country" value="United States">United States</option> & ...

The command 'vue' is not a valid internal or external command

After ensuring that everything was installed correctly, I encountered an issue when trying to create a project. An error message would appear stating that "'vue' is not recognized as an internal or external command". I attempted to reinstall the ...

Inject JavaScript Object Information into Bootstrap Modal

After iterating through each object and assigning its data to an individual div along with a button, I encountered an issue. When testing the buttons, I noticed that only the last object's data was displayed in all of the modal windows. Any suggestion ...

Connecting Next.js to a Database: A Step-by-Step Guide

I am interested in developing an application similar to Samsung Health that will involve heavy querying on a database. I am unsure whether it would be more beneficial to create a custom server using Node.js (with Express.js) instead of using the integrate ...

Converting JSON to CSV using JavaScript

While utilizing this script (which is functioning properly), I encountered an issue where I needed to exclude certain columns (specifically columns 1, 2, 3, and 9) from the extraction process. Here's what I've got so far: $(document).ready(funct ...