TableTools Custom Button Help

TableTools Custom Button Help

morrtymorrty Posts: 29Questions: 6Answers: 0
edited July 2011 in TableTools
Is there an easy way to just create a custom button beside one of the preset buttons that simply links to a static URL.

Basically, I just want a button that links to a different page on my site but I want to keep the current CSS and style of TableTools buttons. I didn't want to go fooling around in CSS to mimic something if there is a built in way for me to do it with TableTools.

Thank you.

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    You can override the buttons as in Allan's example, and probably use any HTML dom element (input buttons, button element, div, link, image).

    [code]
    $(document).ready( function () {
    $('#example').dataTable( {
    "sDom": 'T<"clear">lfrtip',
    "oTableTools": {
    "aButtons": [
    {
    "sExtends": "copy_to_div",
    "sButtonText": "Copy to div",
    "sDiv": "copy",
    }
    ]
    }
    } );
    } );
    [/code]

    http://www.datatables.net/release-datatables/extras/TableTools/plug-in.html

    I haven't done this myself, but it seems straightforward in the example code.
  • morrtymorrty Posts: 29Questions: 6Answers: 0
    edited July 2011
    I can't seem to get a customized button and two presets together. This is what I put in:

    [code]
    $(document).ready(function() {
    $('#datatable').dataTable( {
    "aaSorting": [[0,'asc']],
    "iDisplayLength": 15,
    "aLengthMenu": [[15, 50, 100, -1], [15, 50, 100, "All"]],
    "sPaginationType": "full_numbers",
    "sDom": 'T<"clear">lfrtip',
    "oTableTools": {
    "sSwfPath": "../swf/copy_cvs_xls_pdf.swf",
    "aButtons": [ "xls", "print" ],
    "aButtons": [ {
    "sExtends": "edit",
    "sButtonText": "Edit",
    "sUrl": "?e=edit"
    } ]
    }
    } );
    } );
    [/code]
  • mathiemathie Posts: 36Questions: 0Answers: 0
    edited August 2011
    Here is a working code for me:
    [code]
    TableTools.BUTTONS.gotoURL = {
    "sAction": "text",
    "sFieldBoundary": "",
    "sFieldSeperator": "\t",
    "sNewLine": "
    ",
    "sToolTip": "",
    "sButtonClass": "",
    "sButtonClassHover": "",
    "sButtonText": "Go to URL", // default, change when initiating
    "sGoToURL": "", // default, change when initiating
    "mColumns": "all",
    "bHeader": true,
    "bFooter": true,
    "fnMouseover": null,
    "fnMouseout": null,
    "fnClick": function( nButton, oConfig ) {
    location.href = oConfig.sGoToURL;
    },
    "fnSelect": null,
    "fnComplete": null,
    "fnInit": null
    };
    [/code]


    [code]
    'aButtons'=>array(
    array(
    'sExtends'=>'collection',
    'sButtonText'=>'My Buttons',
    'sButtonClass'=>'DTTT_button_mod',
    'sButtonClassHover'=>'DTTT_button_mod',
    'aButtons'=>array('copy','csv','xls','pdf','print',
    array(
    'sExtends'=>'gotoURL',
    'sButtonText'=>'Example.com',
    'sGoToURL'=>'http://example.com',
    ),
    )
    )
    [/code]

    Good luck,
    Son Nguyen
This discussion has been closed.