skip to Main Content

I have a table containing a list of products. Below the table I have a text field where a barcode is entered, if the barcode is found the matching row in the table should be highlighted. i’ve read through many similar scenarios and as far as I can tell i’m doing everything as I should. I can see in the google dev console that the barcode I enter matches the only product currently in my table however for some reason the css doesn’t get applied… Any idea what i’m doing wrong here?/how I can go about fixing it?

my css:

.found {
    background-color: green;
}

my html table and input field:

<table class="table table-striped">
   <thead>
      <tr>
         <th>Description</th>
         <th>Price</th>                        
         <th>Qty</th>
         <th>Barcode</th>
       </tr>
     </thead>
     <tbody>
        <tr *ngFor="let item of ticket.items" [class.found]="item.Barcode === spotCheckBarcode">
            <td>{{item?.ProductDetail_Name}}</td>
            <td>{{item?.Amount}}</td>   
            <td>{{item?.Qty}}</td>
            <td>{{item?.Barcode}}</td>
          </tr>
       </tbody>
   </table>

   <form role="form" [formGroup]="spotCheckForm" (ngSubmit)="spotCheck(spotCheckForm.value.itemBarcode)">
        <input class="form-control" type="tel" placeholder="Enter item barcode" [formControl]="spotCheckForm.controls['itemBarcode']">
        <button class="btn btn-block" [disabled]="!spotCheckForm.controls['itemBarcode'].valid && busy"><span class="glyphicon glyphicon-search"></span> Search</button>
    </form>

//my ts component function that sets spotCheckBarcode

spotCheck(itemBarcode: number) {                
    let found: boolean = false;     
     for (var i: number = 0; i < this.ticket.items.length; i++) {           
        if (itemBarcode === this.ticket.items[i].Barcode) {
            console.log('found!');
            found = true;               
            this.spotCheckBarcode = itemBarcode;                
        }       
    }       
    if (found == false) {
        console.log(`found in if statement: ${found}`);
        this.showError("Item not found on ticket");
    }           
}

2

Answers


  1. Err, that looks right, but let’s dig it apart.

    So for the css class not being applied, have you tried inspecting the element to see if the class is added to the tr and maybe the styling is being overwritten?

    Is the class attached

    Search for the class

    Is the style overriden

    Login or Signup to reply.
  2. your class is not applied to td. you need to be bit more specific with css for table here.

    .found td { background-color: green; } 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search