Tips for gradually increasing numerical values line by line

Plunker.

After implementing the Plunker provided above, I noticed that the rowId is increasing with alphabets, as shown below:

The component in the Plunker contains buttons labeled with +, ++, and -. When you press the + button, the rowId starts from the first alphabet (i.e. A). Pressing ++ adds to the parent rowId starting with the initial alphabet (e.g. AA). Subsequent presses of ++ continue this pattern (e.g. AAA) and so on.

To see the functionality in action, please visit the Plunker here.

However, I am looking to achieve similar functionality using numbers instead.

When a single plus is pressed, it should display 1. For each ++ press, it should show 111 in sequence. This is the behavior I would like to achieve.

Could someone assist me in implementing this functionality?

var newRow = {
    "rowId": "A"
  }
  $scope.componentList = [];
  $scope.componentList.push(angular.copy(newRow));

  $scope.addParentRow = function(rowId) {
    var newGridRow = angular.copy(newRow);
    var lastChar = getListOfSameLevel(rowId, true); //isParentRow
    var parentId = rowId.length > 1 ? rowId.slice(0, rowId.length - 1) : "";
    newGridRow.rowId = parentId + getNextChar(lastChar);
    $scope.componentList.push(newGridRow);
  }

  $scope.addChildRow = function(rowId) {
    var newGridRow = angular.copy(newRow);
    var lastChar = getListOfSameLevel(rowId, false);
    if (rowId.length === lastChar.length) {
      newGridRow.rowId = rowId + "A";
    } else {
      var parentId = lastChar.length > 1 ? lastChar.slice(0, lastChar.length - 1) : "";
      newGridRow.rowId = parentId + getNextChar(getLastChar(lastChar));
    }
    $scope.componentList.push(newGridRow);
  };

  var getNextChar = function(inputChar) {
    return String.fromCharCode(inputChar.charCodeAt(0) + 1);
  };

  var getLastChar = function(fullStr) {
    return fullStr.slice(-1);
  };

Answer №1

To adjust the starting value of newRow.rowId from A to 1 and modify the consecutive digits from A to 1 in the addChildRow function, follow this example:

if (rowId.length === lastChar.length) {
    newGridRow.rowId = rowId + "1";
}

Click here for your plunker with updated values

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

Utilizing a custom filter for object manipulation within Vuetify's v-autocomplete

When using vuetify v-autocomplete with an object where the object consists of Key-Value pairs, the search functionality is based on the item-text. In my example, I am displaying the object as {1200-Chloride Systems}. Is it possible to make the search funct ...

I'm experiencing an issue where my express-session is being reset with every new request, leading me to question if this is related to the development environment I am using (REACT + EXPRESS)

UPDATE - I have ruled out a development environment issue as the same problem persists in production. Thank you for taking the time to look into this. I've searched through numerous questions and attempted various solutions with no success. To give ...

Leverage videojs-vr within a Vue.js component

I have been experimenting with integrating the videojs-vr package, which I installed through npm, into a Vue.js component. However, I encountered an error: TypeError: videojs is not a function at VueComponent.mounted (VR.vue?d2da:23) at callHook (vue.esm. ...

Entering numerous numerical values across a variety of input fields

My website currently has a form with 6 input fields where visitors need to enter a 6 digit code. To make it easier for them, I want to allow users to simply paste the code we provide into the first input field and have the remaining digits automatically po ...

Observing a class getter within Vue.js

The issue at hand I am facing a challenge in ensuring my page automatically updates when new data is available. I am using Ionic, and have a page that displays all the items collected by the user in a visually appealing manner using an ion-grid. To achiev ...

One way to transfer data from the back end into a two-dimensional array is by retrieving the data and then transforming it into the desired format before sending it to

How can I format backend data into a specific format using JavaScript? Even though I retrieve data from the backend, json_encode($myarry) does not display my data. $query = "SELECT * FROM LOCATIONS"; $result= mysql_query($query); while($row = mysql_fetch ...

What is the best way to manage files in Vue.js?

I am faced with a challenge in storing image files and video files as Blob data. One thing I like is that the uploaded video and image files display instantly, which is pretty cool. I'm not entirely sure if the code below is correct - how can I navi ...

Guide to setting up Nginx to host Rails application and Angular website on one domain

I am eager to configure Nginx to serve both my Rails application (using passenger) and an Angular front end. Essentially, any requests made to / should be routed to Rails, while requests to /admin/* should be directed to the Angular app. I stumbled upon ...

Transferring extensive PHP variables to JavaScript

After checking out different strategies for passing data from PHP to Javascript like this and this, I have concerns about the memory and variable size limits in javascript. Currently, I am transferring large chunks of HTML from PHP to Javascript to dynami ...

Creating an HTML table on-the-fly leads to the opening of a fresh new webpage

Has anyone encountered this issue before? I have a math table coding function, which runs when a button is clicked. However, when I click the button, the table appears on a new page instead of on the same page. <!doctype html> <html> <h ...

Retrieve checkbox selected value using pug and node.js

How can I retrieve the value of a checked checkbox in order to redirect to (href="/player/edit/:id") or (href="/player/delete/: id"), and obtain the player id for editing or deleting? I have omitted other code details such as app.js which includes the ser ...

Leverage the power of PHP array values in your Javascript code

I am facing an issue where I cannot seem to run my javascript functions on a page after retrieving values from a local database using PHP. When the PHP code is included within my javascript, the function does not execute at all. However, if I separate the ...

Can an inner promise in JavaScript not be caught by another promise?

When using promises, I am encountering an issue where the "catch" doesn't seem to catch its child promises. This results in me having to include two instances of the "catch" block. Facility.userHaveAccess(locationObject.created_by, locationObject.fac ...

Scan across a lineup of pictures

I am looking to showcase a series of images in a horizontal alignment, but I want to avoid overloading the screen width. My goal is to allow users to navigate through the images using their mouse - when they move right within the image container, I want t ...

Is it possible to choose several classes with identical names and then trigger a shared function simultaneously?

Is there a way to make this function target all elements with the class ".stop" and stop the video when any of these elements are clicked? window.addEventListener("load", function(event) { window.addEventListener('scroll', checkScroll, false) ...

"An error occurred when processing the JSON data, despite the JSON

Incorporating Ajax syntax for datatables and angularjs has been my current endeavor. Encountering an invalid JSON response with the following: self.dtOptions = DTOptionsBuilder.fromSource([{ "id": 860, "firstName": "Superman", "lastName": "Yoda" }]) How ...

Tips for ensuring an HTML element remains within defined boundaries

Currently working on a visualization tool for search algorithms using React, I've encountered a minor issue when moving the start or end nodes. Upon clicking and dragging the mouse across the grid, the nodes adjust accordingly until reaching the grid& ...

Adding a regional iteration of a library that was unable to be loaded

Recently, I have been experimenting with PhantomJS to capture screenshots of a webpage every five minutes. While the process runs smoothly most of the time, I encountered an issue where the AngularJS library fails to load intermittently. This results in th ...

Prevent clicks from passing through the transparent header-div onto bootstrap buttons

I have a webpage built with AngularJS and Bootstrap. It's currently in beta and available online in (German and): teacher.scool.cool simply click on "test anmelden" navigate to the next page using the menu This webpage features a fixed transparent ...

AngularJS: Creating a unique directive for verifying the availability of a username - no duplicates allowed

I have a registration form that includes a username textbox. I would like to implement a custom directive that will check if the entered username already exists in the database. Here is the api implementation: /*get the unique username*/ $app->get(&ap ...