Adding dynamic row values to a bootstrap table in angular 4 - what's the best approach?

When using an Angular 4 bootstrap table, I am encountering an issue where only the first row value is displayed in the table from the backend when entering a product in the text box and pressing enter. Even though the alert window shows the data for the second row as well, it is not displaying in the table. How can I add multiple row values to the table?

alert: In my alert window, the data being shown is ----[[2,"second",1,1,2,1,1,10.2,1]]

ang.html:

<div class="col-lg-4">                                           
         <label class="col-form-label labal">Product Name</label> 
      <input type="text" class="form-control inputline" placeholder="Search Product Name" name="brand" id="brand" list="brandlist" (change)="getBrandlist($event)"> 
    <datalist id="brandlist" name="brandlist" (change)="getBrandlist($event)">                                                    </datalist>  </div> 
            <table>
                  <thead>
                    <th>#</th>
                    <th>Product Id</th> 
                    <th>Product Name</th>
                    <th>Formulation</th> </thead>
           <tbody>
                    <tr *ngFor="let brand of brandlist; let i = index">               
                    <td>{{ i + 1}} </td>
                    <td>{{brand[i][0]}}</td>
                    <td>{{brand[i][1]}}</td>
                    <td>{{brand[i][2]}}</td>      
                   </tr>                    
          </tbody>
        </table>

component.ts:

brandlist=[];
    getBrandlist($event)
      {
          let val=$event.target.value     
          this.invoiceService.getBrandlist(val).subscribe(data => {this.getTabledata(data)},
            error=>
            {
               console.log('Error occurred On getBrandlist');
            });     
      }
      getTabledata(data)
      {
        if(data!==undefined || data!==null)
        {
          alert(JSON.stringify(data));
          this.brandlist.push(data);     
        }
      }

Answer №1

My understanding is that the information inside the brandlist appears as follows:

[[1,"first",1,1,2,1,1,10.2,1],


[[2,"second",1,1,2,1,1,10.2,1]]]

It was successful for the first array since

row 1 brand[0][0]=which is 1

for

row 2 brand[1][0]=which is [2,"second",1,1,2,1,1,10.2,1]

just try to

alert(JSON.stringify(brandlist));
or cosole.log(brandlist); after adding second item/row

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

What is the best approach to incorporate Column Reordering in react-data-grid?

Within my REACT application, I have incorporated the npm package react-data-grid. They offer a sample showcasing Column Reordering on their website. I wish to replicate this functionality in my own code. Upon reviewing their source code, I am puzzled abou ...

Component-driven form validation in Angular 2

I'm facing a challenge with implementing model-driven form validation in my custom input component. Specifically, I need to figure out how to pass ngControl to the component. In the plunkr demo provided at http://plnkr.co/edit/QTmxl8ij5Z6E3xKh45hI?p= ...

Ways to utilize array reduce for organizing information

Can someone please guide me on how to use the reduce array method to sort entries by date in the following data: const entries = [ {date: 'lu'}, {date: 'lu'}, {date: 'ma'}, {date: 'ma'} ] I would like the ou ...

What is the process for inputting a predefined function into an interface?

In my project, I have a Locale interface that defines the properties of a locale for my component: interface Locale { src: string; alt: string; language: string; i18nFormat: string; } During debugging, I am using the built-in .toSource() function ...

When multiple input fields with an iterative design are using the same onChange() function, the specific event.target.values for each input

I'm in the process of developing a dynamic select button that adjusts based on the information entered into the iterative input fields I've set up. These input fields all utilize the same onChange() function. for (let i = 0; i < selectCount; i ...

Integrating Angular 2 with Java functionalities and JSP

Starting my journey with the Angular 2 framework, I recently dove into working with it. As I delved deeper, many questions began to surface. My initial step was creating an Angular project using the Angular CLI, which went smoothly. However, when I attem ...

What could be causing TypeScript to throw errors regarding the initialState type when defining redux slices with createSlice in reduxToolkit, despite it being the correct type specified?

Here is my implementation of the createSlice() function: import { createSlice, PayloadAction } from "@reduxjs/toolkit"; type TransferDeckModeType = "pipetting" | "evaluation" | "editing"; var initialState: Transfer ...

Testing NextJS App Router API routes with Jest: A comprehensive guide

Looking to test a basic API route: File ./src/app/api/name import { NextResponse } from 'next/server'; export async function GET() { const name = process.env.NAME; return NextResponse.json({ name, }); } Attempting to test ...

What is the best way to get both the id and name of a selected item in Angular?

Within my select field, data is dynamically populated based on names. My objective is to not only capture the selected name but also its corresponding ID. Here's a snippet of my HTML template: <select class="custom-select d-block w-100" id="test" ...

Updating object properties in Typescript

I have written the following Angular 2 TypeScript code: import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) ...

Unexpected silence from the Express web server

I am currently in the process of setting up my Angular application for Server Side Rendering using Angular Universal. Below is the JS file that has been generated by Angular Universal, with minor modifications made to the path and port: import 'zone ...

What is the best way to handle a ReadableStream for a POST request?

I'm currently working on implementing basic CRUD operations using the latest Next.js 13 route handlers in combination with Prisma using TypeScript. This is how my POST request handler appears: export async function POST(req: NextRequest) { const c ...

Navigating within Custom Web Component Angular

Recently, I attempted to create a custom web component using Angular ngDoBootstrap() { const el = createCustomElement(ServicemainComponent, { injector:this.injector }); customElements.define('servicemain', el); } After building the component in ...

Challenges with image cropping in Angular causing performance problems

Utilizing this specific component for image cropping within an ionic/angular8 project has been causing severe performance issues, leading to unresponsiveness on mobile devices. Interestingly, the desktop version does not encounter any problems and the crop ...

Error alert: TypeScript typings issue - Naming conflict with Promise / Failure to locate name Promise

I am currently working on a client/server JavaScript application and I am facing a significant issue with Promises. It appears that they are either undefined or duplicated, and this problem seems to be related to the @types package. npm install --save @ty ...

Invoking a function on an object of a subclass that derives from an abstract class

In the realm of abstract classes, behold this one: export abstract class BaseStepComponent { /** Behold thy base-step ctor */ constructor() { } abstract getValue(): string; } And lo, here is a component that inherits such abstract glory ...

Stop users from switching to other tabs within mat-tab-group without using ViewChild

I am working with a mat-tab-group component in Angular : mat-tab-group class="brand-tabs" [disableRipple]="true" *ngSwitchCase="types.project" (selectedTabChange)="changeProjectTab($event)" [selectedIndex]="selectedProjectIndex" > . ...

The process of transferring a list of objects to another in Typescript

There seems to be an issue with copying values from "all" to "available" and sometimes not getting the value from "available" as well. I've tried multiple methods like using slice(), Array.from(), and simply assigning with =, but none of them seem to ...

Using an early return statement in Typescript triggers the Eslint error "no useless return"

Could you please provide some feedback on the Typescript function I have written below? The function is meant to check for validation, and if it fails, exit out of the submit function. However, ESLint is flagging a 'no-useless-return' error. I&ap ...

What is the best way to find a match for {0} while still allowing for proper

I am working on developing a text templating system that allows for defining placeholders using {0}, similar to the functionality of .Net's string.format method. Here is an example of what I am aiming for: format("{0}", 42), // output ...