jQuery datatables: test if datatables plugin is initialized

后端 未结 6 2352
猫巷女王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 01:08

    First, add a special class name when you're initializing datatables:

    $('.datatable').not('.initialized').addClass('initialized').dataTable()
    

    And now you can tell them apart by class name:

    alert( $('#datatable').hasClass('initialized') )
    

提交回复
热议问题