how do I cast to a jquery datatable
If I don't have a reference to an existing jQuery datatable, how can i get one? i.e. how can I cast a javascript variable to an existing datatable so I can call datatable functions upon it?
I want to do this:
var mytable=(dataTable)$("#mytableid");
mytable.fnGetNodes().serialize();
The following doesn't work:
var mydata= $("#mytableid").fnGetNodes().serialize();
presumably because jQuery doesn't realise I am operating against a datatable.开发者_C百科 To be clear, I know the id of the table, but I don't have a reference to it. Thanks.
To retrieve an existing datatable, just do
var mytable = $('#mytableid').dataTable({"bRetrieve": true});
The correct code is
var mytable = $('#mytableid').dataTable();
That will convert your table to a datatable and allow you to use the API.
精彩评论