简体   繁体   中英

Using Custom editors in grid column with Angular Kendo UI

I am trying to use custom editors for an editable kendo ui grid in my angular app. For some reason( which I am not able to trace) the custom editor is not triggered.

I am expecting the following to be triggered but it does not work.

console.log("Editor Launched", options);

Here is the plunker for the same: http://plnkr.co/edit/WioRbXA3LHVVRQD95nXA?p=preview

app.controller('MainCtrl', function($scope) {
$scope.model = {};
$scope.model.dataSource = new kendo.data.DataSource({
    data: createRandomData(10),
    schema: {
        model: {
            fields: {
                City: { type: "string" }, 
                Title: { type: "string" },
                BirthDate: { type: "date" },
                Age: { type: "number" }
            }
        }
    },
    pageSize: 16,
    editable:true 
});  

$scope.addWWNumEditor= function (container, options) { 
  console.log("Editor Launched", options); 
  $('<input kendo-numeric-text-box k-min="10" k-max="20" style="width: 100%;" data-bind="value:' + options.field + '"/>')
  .appendTo(container);
}



$scope.controlIsDisabled=function(model){
//console.log("model",(model.Age>=50));
var toReturn =  (model.Age>50)?"columnDisabled" : "columnActive";
//console.log('to Return',toReturn);
return toReturn;
}

$scope.model.columns = [  
    { field: 'City', title: 'City' },
    { 
      field: 'Title', 
      title: 'Title',
      template:'<span style="color:red;">EDITABLE</span><span ng-
      class="controlIsDisabled(dataItem)">#=Title#</span>'
    },
    { 
      field: 'Age', 
      title: 'Age',
      template:'<span ng-class="controlIsDisabled(dataItem)">#=Age#</span>' 
     ,
      editor:$scope.addWWNumEditor
    }
];

}); 

Assuming your Plunkr mirrors your actual code, the primary problem I'm seeing is in your binding of k-columns on the grid element.

You currently have k-columns="{{model.columns}}" , but the {{}} are unnecessary here. Changing to k-columns="model.columns" causes your editor function to execute as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM