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

Extending the DataSource with a new method

3 Answers 609 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 02 Oct 2012, 06:35 AM
Hi,
I need to extend the DataSource with a new method.
If I create a new datasource like this:
var myDatasource = new kendo.data.DataSource(.....);

I want to do like this:
myDatasource.myCustomMethod();

How can I extend Datasource with the new method myCustomMethod?

I tried something like this:
$.extend(true, kendo.data.DataSource, {
myCustomMethod: function() {
alert('hello from custom method');
}
});

But it does not work. Please help.

3 Answers, 1 is accepted

Sort by
0
Roger
Top achievements
Rank 1
answered on 02 Oct 2012, 04:00 PM
I think I found the solution to this problem. I can add the new method to the prototype like this:

kendo.data.DataSource.prototype.myCustomMethod = function () {
alert('hello from custom method');
}

Is this the correct way to do it?
0
Atanas Korchev
Telerik team
answered on 03 Oct 2012, 06:42 AM
Hi Roger,

 Yes, this is the right method to extend the prototype of a JavaScript object.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Apu
Top achievements
Rank 1
answered on 03 Oct 2012, 10:42 AM
does this work?

// Extend the data source with your own methods
ds = kendo.data.DataSource.extend({
    transport: {
        read: { url: '/api/v1/data'}
    },
    myCustomMethod: function() { //custom code
    }
});

var dataSource = new ds();
dataSource.myCustomMethod()

Tags
Data Source
Asked by
Roger
Top achievements
Rank 1
Answers by
Roger
Top achievements
Rank 1
Atanas Korchev
Telerik team
Apu
Top achievements
Rank 1
Share this question
or