Reputation: 721
Using angularjs and kendo grid I am trying to call a function on the selection of a checkbox in the grid. But no matter what I do nothing happens in ng-click, not even an error is thrown. I have added console.log() at the top of the method called but nothing shows up. I have tried to add the method in a service in scope and also directly in scope.
Basically my question is how to use ng-click on a checkbox in a kendo grid cell template?
Here is grid binding code:
var cols = this.GetGridColumns(uiConfig.GridColumns);
var grid = $("#kGrid").kendoGrid({
dataSource: {
serverPaging: true,
serverSorting: true,
schema: {
data: "data",
total: "total",
model: {
id: "relatedEntityID"
}
},
pageSize: 10,
transport: {
read: function(options) {
/* read from service */
}
}
},
columns: cols,
scrollable: false,
pageable: { "refresh": true, "pageSizes": true },
sortable: true,
filterable: true,
selectable: "multiple",
change: () => this.onChange()
});
and here is the definition of
GetGridColumns(columns: Array<servicePath.SLF.solutionEngine.Model.Admin.GridColumn>): any
{
var colHeader = new Array();
colHeader.push({
template: '<input type="checkbox" id="cbItem" class="checkbox" ng-click="genericServices.selectRow(\'kGrid\', $event)" />',
headerTemplate: '<input type="checkbox" id="check-all" ng-click="genericServices.ToggleCheckAllInGrid(\'#kGrid\', $event)" />',
width: '30px'});
var column = new servicePath.SLF.solutionEngine.Model.CMs.GridColumnCM();
for (var j=0 ; j < columns.length; j++)
{
column = new servicePath.SLF.solutionEngine.Model.CMs.GridColumnCM();
column.Field = columns[j].BindingName;
column.Title = columns[j].BindingName;
column.ColumnType = columns[j].GridColumnType;
column.HorizontalAlignment = columns[j].HorizontalAlignment;
column.LocalizedName = columns[j].LocalizedLabel;
colHeader.push({ title: column.Name, field: columns[j].BindingName, template: column.Template } );
}
return colHeader;
}
In above code genericServices.ToggleCheckAllInGrid in header template is working perfectly fine.
This is definition of genericServices.
this.selectRow = function (gridId: string, e: any): void {
gridId = '#' + gridId;
console.log(gridId);
var elem = angular.element(e.currentTarget);
var row = elem.closest("tr");
var checked = elem.prop('checked');
if (checked) {
//-select the row
row.addClass("k-state-selected");
} else {
//-remove selection
row.removeClass("k-state-selected");
}
};
Upvotes: 1
Views: 5165
Reputation: 683
You can handle the onclick event on kendo grid header using below code:
$('body ').on('click','.grid .k-header',function(e){
//write your logic..
});
In kendo grid you cannot use ng-click or onClick events. Only href will work.
Upvotes: 1
Reputation: 898
What if you'd use a directive to respond to the click? http://docs.angularjs.org/guide/directive ng-click
is quite jQuery-like.
Upvotes: 0
Reputation: 1205
I guess the angular bootstrap run before the rows added to the grid (to the DOM).
If so, you have to call angular bootstrap manually.
Upvotes: 1