This is a migrated thread and some comments may be shown as answers.

Problems invoking methods of Kendo widget's super

3 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Artur
Top achievements
Rank 1
Artur asked on 23 Jul 2015, 07:25 PM

I'm trying to extend kendoGrid to a custom plugin, but have hard time figuring out what I'm doing wrong when invoking super method refresh(). I would appreciate a hint. Thanks.

(function(){
    var kendo = window.kendo,
            ui = kendo.ui,
            CHANGE = "change";
 
    var MyGrid = ui.Grid.extend({
        init: function(element, options) {
            var that = this;
            ui.Grid.fn.init.call(that, element, options);
            that._dataSource();
        },
 
        options: {
            name: "MyGrid",
            autoBind: true
        },
 
        _dataSource: function() {
            var that = this;
            that.dataSource = kendo.data.DataSource.create(that.options.dataSource);
 
            that.dataSource.bind(CHANGE, function() {
                console.log(ui.Grid.fn);
                console.log(that.dataSource);
                ui.Grid.fn.refresh.call(that); // <- problematic
            });
 
            if (that.options.autoBind) {
                that.dataSource.fetch();
            }
        }
    });
    ui.plugin(MyGrid);
})(jQuery);
 
$(function(){
    $('#MyGrid').kendoMyGrid({
        columns: [
         { field: "FirstName", title: "First Name"},
         { field: "LastName", title: "Last Name" }
        ],
        dataSource: {
            data: [
            { FirstName: "Joe", LastName: "Smith" },
            { FirstName: "Jane", LastName: "Smith" }
            ]
        }
    })
})

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 27 Jul 2015, 10:29 AM
Hello Artur,

In general, the Grid's refresh method expects parameters that are passed from the DataSource's change event. My guess is that you need to pass them as a second argument:
that.dataSource.bind(CHANGE, function(e) {
    ui.Grid.fn.refresh.call(that, e);
});

For those who are interested in extending Kendo UI widgets, I would suggest review the following help document:
Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Artur
Top achievements
Rank 1
answered on 27 Jul 2015, 09:33 PM

Dear Geirgi,

As per your guess, unfortunately passing the event did not help.

As per the link you refer to - I have been through it. What is a bit deceiving - is that the code employs kendo.template() hreas not every plugin employs templates, some of them are just meant as subclasses to share events and methods... 

Regards,
Artur

0
Artur
Top achievements
Rank 1
answered on 27 Jul 2015, 09:37 PM
Hold on! it does work - I uncommented the autoBind part. It turned out to be offending.
Tags
Grid
Asked by
Artur
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Artur
Top achievements
Rank 1
Share this question
or