DataTable - Pagination and Filter don't work for JavaScript generated table

Solution 1:

Try inserting the table into the DOM first, and then initializing it as a DataTable. You'll also want to make sure you have a valid thead in the table too:

https://jsfiddle.net/u7yhx9fL/10/

var keywords = [["dog", 2],["table", 3],["chair", 4],["dog", 2],["table", 3],["chair", 4], ["dog", 2],["table", 3],["chair", 4],["dog", 2],["table", 3],["chair", 4],["dog", 2],["table", 3],["chair", 4]];
var id=0;

function buildKeywordTableString(keywords){

    var dataSet = new Array();
        
    for (var i = 0; i < keywords.length; i++){
      dataSet.push([keywords[i][0],keywords[i][1]]);    
    }
    
    var table =  '<table id="table' + id + '" cellpadding="0" cellspacing="0" border="0" class="display"><thead><tr><th>Keyword</th><th>F</th></tr></thead><tbody></tbody></table>';
    $('body').append(table);
    $('#table' + id).dataTable({
        "data": dataSet,
        "bFilter":true,
        "paging": true,
        "bPaginate":true
    });
    
    id++
}

buildKeywordTableString(keywords);
buildKeywordTableString(keywords);