Extending the DataSource with a new method

4 posts, 0 answers
  1. Roger
    Roger avatar
    6 posts
    Member since:
    Oct 2011

    Posted 02 Oct 2012 Link to this post

    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.
  2. Roger
    Roger avatar
    6 posts
    Member since:
    Oct 2011

    Posted 02 Oct 2012 Link to this post

    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?
  3. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 03 Oct 2012 Link to this post

    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!
  4. Apu
    Apu avatar
    1 posts
    Member since:
    Oct 2012

    Posted 03 Oct 2012 Link to this post

    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()

Back to Top