링크의 예는 위젯 클래스를 확장합니다. 이것은 모든 Kendo UI 위젯을 파생시키는 기본 클래스입니다. 귀하의 경우, 키노 그리드를 확장하고 거기에서 기능을 추가하고자합니다. init 메소드의 시그니처는 Kendo 내부에서 호출되기 때문에 변경할 수는 없지만 필요한 옵션을 쉽게 사용자 정의 할 수 있습니다. 기본 패턴은 다음과 같습니다.
(function ($, undefined) {
if (!kendo.ui.MyGrid) {
var base = kendo.ui.Grid;
var MyGrid = base.extend({
init: function (element, options) {
// Call the base class's init.
base.fn.init.call(this, element, options);
// Add initialization...
this.myField1 = options.myOption1;
// If you want to watch changes in the dataSource
// attached to the grid, you could use this. Of
// course you don't even need to subclass to do this
// but you get the point.
this.dataSource.bind("change", function(e) {
if (that.options.myCallback) {
that.options.myCallback.call(that, e);
}
};
},
// Add default options...
options: {
myOption1: "Hello",
myOption2: "World",
myCallback: undefined,
}
// Add events...
events: [
"myEvent1",
"myEvent2"
],
// Add fields...
myField1: "Goodbye",
// Add methods...
myMehod: function (a, b, c) {
// Do something...
}
}
// Register the new widget.
kendo.ui.plugin(MyGrid);
}
})(jQuery);
이제 MyGrid에는 추가 된 기능과 함께 Grid의 모든 기능이 추가되었습니다. 그리드와 마찬가지로 새 인스턴스를 만듭니다.
$("#someElement").kendoMyGrid({
// Add options for standard kendo Grid and your new options...
myCallback: function (e) {
alert(e.action);
}
});
감사합니다. moomoo! 지금은 코드를 테스트 할 수 없지만 답변을 주셔서 감사합니다. 그것을 보았을 때,'dataSource'의'change' 이벤트가 가로 챈 채 멈추었 을까요? 아니면 전파되어서 사용자가 생성자에서 자신의 핸들러를 여전히 할당 할 수 있을까요? – user776686
예, 이것은 매력처럼 작동합니다! 나는'kendoMyGrid'에 생성자를 다시 할 필요조차 없습니다 - 디폴트'kendoGrid'는 여전히 작동합니다. – user776686
쿨! 나는 실제로 모든 종류의 작업을 수행하기 위해 거의 4K 줄의 코드를 Grid에 추가했습니다 (GridEx라고 부릅니다). 내가 공유 할 수있는 것은 아닙니다. – moomoo