jQuery datatables: test if datatables plugin is initialized

后端 未结 6 2363
猫巷女王i
猫巷女王i 2021-02-13 00:34

I want to check if a table element with say, id=\"datatable\" is datatables-initialized. Something like this:

if ($(\'#datatable\').dataTable().initialized) {
           


        
6条回答
  •  爱一瞬间的悲伤
    2021-02-13 00:43

    After you've called .dataTable() does it do anything to the table that makes it identifiable? i.e. does it add a new class "initialised" or something like that? If so, you could just loop through the items like so:

    $('.datatable').each(
        function(index, element) {
            var _table = $(element);
            if (_table.hasClass('initialised')) {
                // Do stuff
            } else {
                // Do stuff
            }
        }
    );
    

    Apologies if this isn't what you mean. It's not clear in your question what "dataTable()" actually does.

提交回复
热议问题