Adding custom functions in the initialization of the dataTable

Adding custom functions in the initialization of the dataTable

LeronLeron Posts: 2Questions: 1Answers: 0

Hello to everyone first!
I've seen this question once or twice, but yet I want to give it a shot since I'm beginner not only in dataTables but in Java Script in general. My current task is to customize the dataTable(v1.10) mostly with buttons, textboxes and dropdowns in the toolbar but doing this without writing into the core of the DataTable itself. In other words I have a file CustomDT.js where all my changes should be placed. So this was the easy part since there is a very good example :

$.fn.dataTableExt.oApi.fnGetHiddenTrNodes = function (oSettings) {...

which allows me to add custom functions and thus all the logic I need. However the problem is that in this example the way to actually execute this method is by binding it to the click event of a button and clicking it :

$('#button').on('click', function () {
oTable.fnGetHiddenTrNodes();
});

Which is not very useful to me. There are two things that I want to achieve:

1 - To keep the initialization logic as consistent as possible, which means that my best scenario is when I initialize my dataTable like so:

var otable = $('#example').dataTable( {
"bServerSide": true,
"bAutoWidth": false,
.....
"myCustomFunction1": true,
"myCustomFunction2": false,
"myCustomFunction3": true,

and so on.

2 - To keep thins separated - the core files stay as they are, and my custom logic to be placed in different place.

So at the end I think there are actually two questions - is it possible to implement the same behavior with custom functions, keeping the extra logic separated and if not, I would really appreciate if the more experienced users here share their opinion on what would be the next best way to do this. I've looked through some of the extensions for dataTable and I've noticed that most of them (if not all) are used by creating new instance of the extension. Also, they are pretty complicated themselves and I would like to get thing working so would really appreciate some guidelines on how to implement a similar behavior.

Thanks
Leron

This discussion has been closed.