javascript - AngularJS kendo grid with custom command which includes template doesn't handle events -


i have angularjs - kendo ui grid-based solution. in controller grid have placed following code:

$scope.customclick = function(e) {            $scope.$apply(                 function() {                     e.preventdefault();                     alert('customclick');                 }); };   $scope.gridoptions = {     datasource: $scope.griddata,     pageable: {         refresh: true,         pagesizes: true,         buttoncount: 5     },     scrollable: true,     sortable: true,     filterable: true,     selectable: true,     editable: "inline",     columns: [         {           command :[ {text: "", template: '<input type="checkbox" id="check-all"  />', click: $scope.customclick} ]          },         {field: "documentkey", title: "document key"},         {field: "sender", title: "sender"},         {field: "recipient", title: "recipient"},         {field: "changedate", title: "receivedby time"},         {field: "flowcomment", title: "comment"},         {field: "location", title: "location"}         ]     };  }); 

added checkbox displayed fine, don't know how handle click event. $scope.customclick not triggered after clicking on check box.

a old question, user had found solution long ago, in case google search gets question, it's have answer. javascript combined libraries kendoui , angularjs allow solve problems using several different approaches, here 1 of them:

say have grid defined this:
<div kendo-grid="kendo.mygrid" k-options="gridoptions"></div>

your javascript code define grid might this:

$scope.gridoptions = {             datasource: new kendo.data.datasource({                 data: datafromsomelocalvariablemaybe,                 pagesize: 10             }),             sortable: true,             pageable: {                 pagesizes: [10, 20, 50]             },             columns: [{                 field: "column1",                 title: "column 1",                 width: "100px"             }, {                 field: "column2",                 title: "column 2",                 width: "120px"             }, {                 command: [{                     template: "<span class='k-button' ng-click='dosomething($event)'> something</span>"                 }, {                     template: "<span class='k-button' ng-click='dosomethingelse($event)'> else</span>"                 }],                 title: " ",                 width: "100px"             }]         }; 

notice $event passed ng-click call function. $event contains actual click event data.

if this, need have these 2 functions defined:

$scope.dosomething = function($event) {     // element clicked     var sender = $event.currenttarget;      // kendo grid row contains clicked element     var row = angular.element(sender).closest("tr");      // data bound item row     var dataitem = $scope.kendo.mygrid.dataitem(row);      console.log(dataitem); };  $scope.dosomethingelse = function($event) {     // else }; 

and that's it.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -