TableTools Direct Initialization is not working

TableTools Direct Initialization is not working

dharmeshpatel82dharmeshpatel82 Posts: 15Questions: 2Answers: 0
edited April 2014 in TableTools
Hello,

I have initialized TableTools inside DataTable Initialization and It works perfectly, but For some reason I need to initialize TableTools on Button Click. so I Tried a test, I am initializing it just after DataTable got initialized.
[code]
$(document).ready(function () {
var oTable = $('#dTTTIntEx').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bProcessing": true
});
var oTableTools = new TableTools(oTable, {
"aButtons": [
"copy",
"csv",
"xls",
"pdf",
{ "stype": "print", "sButtonText": "Print me!" }
]
});

$('#demoDTTT').before(oTableTools.dom.container);
});
[/code]
I am getting this error :
[quote]
Line: 1400 - var oTableTools = new TableTools(oTable, {
Error: Object doesn't support this action
[/quote]

Can anybody have a suggestion for me. Thank you.

Replies

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Which version of TableTools are you using? Try `new $.fn.dataTable.TableTools( ... );` .

    Allan
  • dharmeshpatel82dharmeshpatel82 Posts: 15Questions: 2Answers: 0
    Hello Allan,

    Thank you very much for your fast response, I am using TableTools-2.2.0, Your solution works in that? Why we call TableTools like this, Please tell me? and I think somebody needs to update Direct initialization example in this site, That is not working.

    Thank you very much for your help.
  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Should do. You would initialise TableTools that way as the `TableTools` global object is going to be removed in future versions - see: http://next.datatables.net/release-datatables/extensions/TableTools/examples/new_init.html

    Allan
  • dharmeshpatel82dharmeshpatel82 Posts: 15Questions: 2Answers: 0
    Hello Allan,

    [quote] new $.fn.dataTable.TableTools( ... ); [/quote] works pretty well. Thank you very much for your guidance.
    How do I close this discussion?
  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    It will close automatically in a few months :-). I'm going to be updating the forum soon to be able to mark a thread as resolved. But for now, we just let it fade into history!

    Allan
  • juankmilo91juankmilo91 Posts: 3Questions: 1Answers: 0

    please can you put your script here, i need help whit the same problem

  • dharmeshpatel82dharmeshpatel82 Posts: 15Questions: 2Answers: 0
    var oTableTools = new $.fn.dataTable.TableTools(oTable, {
        "sRowSelect": "single",
        "fnRowSelected" : function (nodes) {
                 var aData = oTable.fnGetData(nodes[0], "" + I_REC_Index + "");
            $(tableWrapperDivId).attr("data-cpnIndex", aData);
        },
        "fnRowDeselected" : function (nodes) {
            $(tableWrapperDivId).removeAttr("data-cpnIndex");
        },
        "sSwfPath" : "Content/TableTools-2.2.0/swf/copy_csv_xls_pdf.swf",
        "aButtons": [{
            "sExtends": "text",
            "sButtonText": "Export Tool",
            "sButtonClass": "ExportExcelClass",
        }]
    });
    

    Where "oTable" is Datatable object.

  • dharmeshpatel82dharmeshpatel82 Posts: 15Questions: 2Answers: 0
    var oTableTools = new $.fn.dataTable.TableTools(oTable, {
        "sRowSelect": "single",
        "fnRowSelected" : function (nodes) {
            var aData = oTable.fnGetData(nodes[0], "" + I_REC_Index + "");
            $(tableWrapperDivId).attr("data-cpnIndex", aData);
        },
        "fnRowDeselected" : function (nodes) {
            $(tableWrapperDivId).removeAttr("data-cpnIndex");
        },
        "sSwfPath" : "Content/TableTools-2.2.0/swf/copy_csv_xls_pdf.swf",
        "aButtons": [{
            "sExtends": "text",
            "sButtonText": "Export Tool",
            "sButtonClass": "ExportExcelClass",
        }]
    });
    

    Where oTable is DataTable Object

  • dharmeshpatel82dharmeshpatel82 Posts: 15Questions: 2Answers: 0
    var oTableTools = new $.fn.dataTable.TableTools(oTable, {
        "sRowSelect": "single",
        "fnRowSelected" : function (nodes) {
            var aData = oTable.fnGetData(nodes[0], "" + I_REC_Index + "");
            $(tableWrapperDivId).attr("data-cpnIndex", aData);
        },
        "fnRowDeselected" : function (nodes) {
            $(tableWrapperDivId).removeAttr("data-cpnIndex");
        },
        "sSwfPath" : "Content/TableTools-2.2.0/swf/copy_csv_xls_pdf.swf",
        "aButtons": [{
            "sExtends": "text",
            "sButtonText": "Export Tool",
            "sButtonClass": "ExportExcelClass",
        }]
    });
    

    Where oTable is DataTable Object

  • kingrichard2005kingrichard2005 Posts: 7Questions: 0Answers: 0
    edited January 2015

    Hi allan, first thank you and the DT community for your efforts, this is an excellent library. I had a similar issue as dharmeshpatel82 regarding direct initialization of TableTools which also resolved by your recommended (updated) method. Basically I had my table initialization setup as follows:

    // Non-working table tools initialization
     myTble.dataTable( {
            "sDom": '<"clear">rt',
            "bJQueryUI": true,
            "bProcessing": true,
            "bDestroy": true,
            "bAutoWidth": true,
            "iDisplayLength": 100,
            "aaData": aaData,
            "oTableTools": {
                "sRowSelect": "single",
                "fnPreRowSelect": function ( e, nodes ) {
                    // THIS NEVER GETS TRIGGERED
                    return true;
             }
            }
        });
    
    
    // Working table tools initialization (using updated method)
    var oTableTools = new $.fn.dataTable.TableTools(myTble, {
            "sRowSelect": "single",
            "fnRowDeselected" : function (nodes) {
                //THIS GETS TRIGGERED
            }
        });
    

    We're using the legacy Datatables version 1.9.4, but your recommended method of initialization still worked as expected. I was just curious why the first method doesn't work for this table since it seemed to work fine on another datatable I initialized in the same DOM context. Is this becuase the TableTools global object, which you mention would be removed in future releases, can only refer to one table at a time?

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    I was just curious why the first method doesn't work for this table since it seemed to work fine on another datatable I initialized in the same DOM context.

    Because there is no T option in your sDom option. TableTools is only automatically initialised by DataTables if you include that option.

    The newer extensions are more flexible and the rewrite of TableTools will follow the new pattern.

    Allan

This discussion has been closed.