Table tool buttons not rendered when using text file for passing language info to DT

Table tool buttons not rendered when using text file for passing language info to DT

matthewjmatthewj Posts: 39Questions: 2Answers: 0

When passing language information to DT from a text file the table toolbar is not rendered. This happens when I initialize table tool by using API. Below is the full code: I am using DataTables 1.10.0 package. But this problems is also in 1.9.4 package

$(document).ready(function() {
    var otable = $('#table').dataTable( {
        "sDom": '<"H"f<"clear">><"top"i>t<"F">rS',
        "bJQueryUI": true,
        "bServerSide": true,
        "sScrollX": "100%",
        "sScrollY": "400px",
        "bScrollCollapse": true,
        "bAutoWidth": false,
        "bProcessing": true,
        "bDeferRender": true,
        "sAjaxSource": "${pageContext.request.contextPath}/list.html",
        "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
            oSettings.jqXHR = $.ajax( {
                "url": sSource,
                "data": aoData,
                "type": "POST",
                "dataType": 'json',
                "success": function(data) {
                    var hasError = fnCheckError(data);
                    if(!hasError) {
                        fnCallback(data);
                    }
                }
            });
        },
        "aoColumns": [
            { "sTitle":"Title", "mData": "lvlTitle", "sClass": 'col_header' }
        ],
        "oLanguage": { 
            "sUrl": "${pageContext.request.contextPath}/dtlang.txt"
        }
        
    } );
    
    var oTableTools = new TableTools( otable, {
        "sRowSelect": "single",
        "aButtons": [ 
            { 
                "sExtends": "text",
                "sButtonText": "New",
                "bHeader" : false,
                "fnClick": function (nButton, oConfig) {

                }
            }
        ]
    });
    
    $('div#table_filter').before( oTableTools.dom.container );
});

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Use initComplete to construct the TableTools object and insert it into the DOM. The loading of the language file is done asynchronously, so the table initialisation statement completes before the table has been fully created (there is no #table_filter element on the page at that point).

    Allan

  • matthewjmatthewj Posts: 39Questions: 2Answers: 0

    Voila! It worked.

    by putting it in initComplete worked

    "fnInitComplete": function(settings, json) {
        $('div#table_filter').before( oTableTools.dom.container );
    }
    

    Thanks Allan

    How can I make this "Answered"? I dont see the message: Did this answer the question? Yes • No for this discussion.

This discussion has been closed.