Drop down menu with name instead of ID in Jhipster


Problem:
how to list item name in drop down instead of ID.




Solution 1 :

In entity relationship use name field so that the value will appear directly in the drop down, for example in the below entity relationship food item name directly appear in the Menu entity instead of food item ID .

relationship OneToMany {
FoodItem to Menu{fooditem(foodname)}
Vendor to Menu{vendor(name)}
Vendor to Order{vendor(name)}
FoodItem to Order{fooditem(foodname)}
}

Solution 2 :
Modify the entity html page remove ID and add field name which you want to show.
   <td>
                    <div *ngIf="vendor.menu">
                        <a [routerLink]="['../menu', vendor.menu?.id, 'view' ]" >{{vendor.menu?.id}}-{{vendor.menu?.foodname}}</a>
                    </div>
                </td>





Full entity relationship for reference. 

entity Vendor
{
name String required
}
entity Menu
entity FoodItem {
foodname String required ,
    cost Long required
}
/*
// an ignored comment
/** not an ignored comment */
entity Order {
    employeeid String required,
    phone String,
    date Instant required,
cost Long,
    status Status,
}

enum Status {
    INPROGRESS, READYTOSERVE, COMPLETED
}
relationship OneToMany {
  FoodItem to Menu{fooditem(foodname)}
  Vendor to Menu{vendor(name)}
  Vendor to Order{vendor(name)}
  FoodItem to Order{fooditem(foodname)}
}
relationship ManyToOne {
FoodItem{user(login)} to User
Menu{user(login)} to User
}



0 comments:

Post a Comment