vendredi 3 avril 2015

How to select items in the list without using the checkbox in angular?

I have a problem replacing the checkbox with one click select for adding items to list. Currently its working with the checkbox but I want it to replace with one click selection. It is in a template. Sample code of the list where I retrive the items to add them in to the other list:



"<td #:columns[0].hidden ? 'style=display:none' : '' #><div class='text-center'><input type='checkbox' ng-class='{'selected':$index == selectedRow}' class='checkbox' ng-checked='selectedOrganizations.indexOf(dataItem.id)>-1' ng-click='setClickedRow($index)''></input></div></td>" +


And the angular part is this:



$scope.onOneClick = function (e, id) {
var element = $(e.currentTarget);
var selected = element.is(':selected'),
row = element.closest("tr"),
grid = angular.element('#modalOrganizationsGrid').data("kendo-grid"),
dataItem = grid.dataItem(row);
if (selected) {
$scope.selectedOrganizations.push(id);
} else {
$scope.selectedOrganizations.splice($scope.selectedOrganizations.indexOf(id), 1);
}
};


I tried with this from a plunk sample:



$scope.selectedRow = 0;

$scope.selectedRow = function (index) {
$scope.selectedRow = index;
};


But it doesn't work. Do I have to use ng-select or ng-repeat or ng-options for getting the result? Any suggestions?


Aucun commentaire:

Enregistrer un commentaire