You Old Fool
You Old Fool

Reputation: 22950

DataTable or dataTable?

On the DataTables website there are a number of examples given for functions on a table. In some they use:

table = $('#example').dataTable();

in others...

table = $('#example').DataTable();

It took me a while to notice that some functions work only on the former, while others only on the later. This is really confusing and I haven't been able to find any clarification on the difference between the two.

Currently I am at a standstill as I require two functions that only work on one or the other:

table.fnAdjustColumnSizing

and

table.column(x).search(this.value).draw(); 

Anyone have an idea for how to build the table so both of the above can work?

Upvotes: 0

Views: 1485

Answers (2)

davidkonrad
davidkonrad

Reputation: 85558

See the upgrade facts -> http://www.datatables.net/upgrade/1.10-faqs

Q. I get an error message when trying to access one of the old fn* style API methods A. This is the inverse of the above issue. DataTables 1.9 attached a number of functions (all starting with fn) to the jQuery object. The old API is still available, but you must use $().dataTable() to access the jQuery object.

Simply use

$(window).bind('resize', function () {
    $('#example').dataTable().fnAdjustColumnSizing();
});

see demo -> http://jsfiddle.net/uL5x4dg1/ if you want to use the old API functions along with the new DataTable() API. dataTable() does not reinitialise the table, it just returns the oldstyle jQuery object.

Upvotes: 2

isherwood
isherwood

Reputation: 61083

DataTable (uppercase first letter) indicates a method from the new api. The latest versions of DataTables still support the old methods, but you should use the new api when possible.

http://datatables.net/manual/api#Accessing-the-API

This is probably what you need for your question:

table.columns.adjust().draw();

https://datatables.net/reference/api/columns.adjust()

Upvotes: 2

Related Questions