Search code examples
angulartypescriptkendo-combobox

How to get both text and value from kendo combobox using TypesScript(angular)


I need to get both text and value from the kendocombox box onchange event. But i am able to get only the value field. Text is not displaying.

HTML:

 <kendo-combobox [data]="taxRatesource" [placeholder]="'Select'" [textField]="'text'"
                 [valueField]="'value'" (valueChange)="taxRateGridChange($event)"
                 [(ngModel)]="datachild.intTaxRateCode">
                </kendo-combobox>

TS:

taxRateGridChange(event) {
const textVal = event;
}

const textVal contains only the value , but want text too. Kinldy help to sort out this issue.


Solution

  • Generally selects or combos return a value of selected option. But you can find selected value from your dataSource.

      taxRateGridChange(value) {
        let textVal;
        if (value) {
          const selectedOption = this.dataSource.find((entity) => entity.value === value);
          textVal = selectedOption ? selectedOption.text : null;
        } else {
          textVal = null;
        }
      }