jQuery datatables: test if datatables plugin is initialized

后端 未结 6 2376
猫巷女王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

    I have used callback() function to do the same in my scenario. Thought of sharing this as an alternate approach

    /* During Initialization */
    var isTableInitialized = false;
    $('#datatable').dataTable({/* your dataTable configurations*/},initializeDT());
    
    /* Implement a callback function to set the value */
    function initializeDT() {
        isTableInitialized = true;
    }
    

    Later in code..

    /* Checking for Initialization is easier*/
    if(isTableInitialized) {
        /* Do something here */
    } else {
        /* Do something here */
    }
    

提交回复
热议问题