DataTable() or dataTable()?

DataTable() or dataTable()?

chico3001chico3001 Posts: 4Questions: 1Answers: 0

Sorry if this question seems strange, i'm a bit noob on javascript xD

What is the difference between $( selector ).DataTable() and $( selector ).dataTable();? and what is the correct way to use the plugin

I ask this because i couldnt make ajax to work, later i realized that the example is $( selector ).DataTable(); and i was using $( selector ).dataTable(); but i cannot understand the need to use 2 function names with only a capitalization diference

Is it for compatibility between datatable versions?

Regards...

This question has an accepted answers - jump to answer

Answers

  • creatorDotJScreatorDotJS Posts: 20Questions: 6Answers: 0

    I'm a noob as well and was reading more the difference. If you go to http://www.datatables.net/manual/installation and scroll towards the bottom you will see the following:

    "Upgrade note:
    If you are upgrading from DataTables 1.9 or earlier, you might notice that a capital D is used to initialise the DataTable here. $().DataTable() returns a DataTables API instance, while $().dataTable() will also initialise a DataTable, but returns a jQuery object.

    Please refer to the API manual for further information."

    I've tried both and so far I haven't seen a difference in my functionality, however, I'm still unclear if you are supposed to use one for certain functions and one for another? Pick one and stick with it? If you need to use an API or Extension use only the DataTable?

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin
    Answer ✓

    In terms of initialisation and the options you can pass in, there is absolutely no difference between the two. The difference comes from the returned object.

    Using $().dataTable() it returns a jQuery object, which you can use for jQuery style chaining (.e.g addClass() and all the other jQuery methods are available). This is also the option to use for the old style 1.9- API, although I would suggest avoiding that if you are new to DataTables.

    Using $().DataTable() returns a DataTables API instance, which you would use if you want to work with the DataTables API.

    See also the API manual on this topic and the FAQ.

    Allan

This discussion has been closed.