开发者

how do I cast to a jquery datatable

开发者 https://www.devze.com 2023-02-17 11:09 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消