Proper Way To Extend DataTable

Proper Way To Extend DataTable

NahuelNahuel Posts: 2Questions: 0Answers: 0
edited June 2011 in DataTables 1.8
Hi,
I want to set some parameters as default for all my DataTable instances. I wonder if there's a proper way to extend the class like jQuery UI widgets [0]?

Thanks in advance
Nahuel

[0] http://wiki.jqueryui.com/w/page/12138135/Widget-factory

Replies

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    At the moment not really the same as what jQuery UI uses - this is a short coming in DataTables which will be addressed in future (some of the DataTables plug-ins do it that way). Having said that, what you can do is something like this:

    [code]
    var defaults = {
    "bSort": false,
    "bProcessing": true
    };

    $('#example').dataTable( $.extend( true, {}, defaults, {
    "bFilter": false
    } ) );
    [/code]

    Which is basically the same thing - you have your own defaults objects and control it rather than DataTables managing it.

    Allan
  • NahuelNahuel Posts: 2Questions: 0Answers: 0
    Allan, thanks for your answer. It works, but there are some cases where I can't see how to implement things in a simple way, in paricular, click listeners.

    Thanks agian.
    Nahuel
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    I'm not quite sure what you mean I'm afraid - DataTables currently doesn't generate any custom events - so you can't assign listeners to the instance, regardless of the defaults. You can use callback functions using the method above, or you could use jQuery live events to have a "default" listener, depending on what it is you want to do.

    Allan
This discussion has been closed.