How to pass selected id from kendo combo box to angular function
I am using a table and the body of the table is in ng-repeat. I want to pass the id of the selected item through the kendo combo box, but it always passes the last item id to the function.
<tbody>
<tr ng-repeat="hours in GetHours">
<td style="width:2%"><input type="checkbox" ng-model="hours.Selected" ng-change="RefreshSelectedDealsCount()" /></td>
<td style="width:25%;text-align:left">{{hours.ContactName}}</td>
<td style="width:25%;text-align:left">{{hours.Hours}}</td>
<td style="width:20%;text-align:left"><select id="combobox" kendo-combo-box class="form-control" k-ng-model="hours.DealName"
ng-click="GetDeals(hours)" k-options="myDealList" style="width: 190px" k-placeholder="'Select deal'"></select></td>
</tr>
</tbody>
// In controller JS →
//Get All the Deals Related to contacts
$scope.GetDeals = function (hours)
{
$scope.CurrentHour = hours;
}
// For Kendo Combo box in JS Controller
$scope.DealDataSource = {
serverFiltering: true,
transport: {
read: {
dataType: "json",
url: '/Project/GetContactDeals',
data: {
id: function () {
return $scope.CurrentHour.FKContactID;
},
},
}
}
};
$scope.myDealList = {
dataSource: $scope.DealDataSource,
dataTextField: "Todeal",
delay: 300,
autoBind:false,
highlightFirst: true,
select: function (ev) {
$scope.DelID = 0;
var dealID = this.dataItem(ev.item.index()).Dealid;
$scope.DelID = dealID;
$scope.CurrentHour.DealID = dealID
},
}
+3
source to share
1 answer
You can try with this code, I think it will help you
<td style="width:20%;text-align:left"><select kendo-combo-box k-data-text-field="'Subject'" k-data-value-field="'DealID'" k-ng-model="hoursSelectedDeal" k-on-change="getSelectedContact(hoursSelectedDeal,kendoEvent)" k-data-source="hours.DealList" style="width: 190px" k-placeholder="'Select deal'"></select></td>
$scope.getSelectedContact = function (item,e) {
console.log(e.sender.$angular_scope.this.hours);
for (var i = 0; i < $scope.GetHours.length; i++) {
for (var j = 0; j < $scope.GetHours[i].DealList.length; j++) {
if ($scope.GetHours[i].DealList[j].DealID == item) {
$scope.selectedRow.DealID = $scope.GetHours[i].DealList[j].DealID;
$scope.selectedRow.DealName = $scope.GetHours[i].DealList[j].Subject;
$scope.selectedRow.ContactID = $scope.GetHours[i].FKContactID;
}
else
{
$scope.selectedRow.DealID = 0;
$scope.selectedRow.DealName = e.sender.$angular_scope.hoursSelectedDeal;
$scope.selectedRow.ContactID = e.sender.$angular_scope.this.hours.FKContactID;
}
}
}
var index = -1;
for (var k = 0; k < $scope.AllSelectedContacts.length; k++) {
if ($scope.AllSelectedContacts[k].ContactID == $scope.selectedRow.ContactID) {
if( $scope.AllSelectedContacts[k].DealID == $scope.selectedRow.DealID)
{
index = 1;
$scope.AllSelectedContacts.splice(k);
}
else
{
index = 1;
$scope.AllSelectedContacts[k].DealID = $scope.selectedRow.DealID;
$scope.AllSelectedContacts[k].DealName = $scope.selectedRow.DealName;
}
}
}
if (index == -1) {
$scope.AllSelectedContacts.push({
DealID: $scope.selectedRow.DealID,
DealName: $scope.selectedRow.DealName,
ContactID: $scope.selectedRow.ContactID
});
}
console.log($scope.selectedRow);
}
+2
source to share