Skip to content

Override base functions

Roberto Prevato edited this page Oct 15, 2015 · 3 revisions

The KingTable widget offers two ways to override base functions:

  • define a new type of KingTable, using its extend function
  • pass a second parameter inside the constructor: it will be used to extend the instance

Using the extend function

The KingTable adopts the extend function of Backbone library. This example shows how to use the extend function, to define a custom type of KingTable:

var SpecificTable = $.KingTable.extend({
  
  mixinAjaxPostData: function () {
    //overrides the base mixinAjaxPostData
  }

});

//create an instance of SpecificTable:
var instance = new SpecificTable({
  //options that would normally used
  url: "/api/some/url",
  $el: $("#container")
});

//render
instance.render();

The strength point of this approach, is that it makes possible to define reusable types.

Using the constructor parameter

This example shows how to override base functions, by using the constructor:

var instance = new $.KingTable({
  //options as first parameter
}, {
  //the second parameter is used to extend directly the instance, even overriding base functions
  mixinAjaxPostData: function () {
    //overrides the base mixinAjaxPostData
  }
});

The strength point of this approach, is that it is faster; and of course doesn't override the base definition of the KingTable prototype.

Clone this wiki locally