mtzStrada
mtzStrada

Reputation: 63

how to add tabletools to existing datatables?

OK guys, I have a page with a dinamic table using jquery datatables

 <div class="widget">

<div class="widget-head">
<h5>Usuarios</h5>
</div>

<div class="widget-body">
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table cellpadding="0" cellspacing="0" border="0" id="data-table" width="100%">
<thead>
<tr>
<th><?php echo lang('index_fname_th');?></th>
        <th><?php echo lang('index_lname_th');?></th>
        <th><?php echo lang('index_email_th');?></th>
        <th><?php echo lang('index_groups_th');?></th>
                <th><?php echo lang('index_code_th');?></th>
        <th><?php echo lang('index_status_th');?></th>
        <th><?php echo lang('index_action_th');?></th>
                <th><?php echo lang('index_net_th');?></th>
</tr>
</thead>
<tbody>
                                    <?php foreach ($users as $user):?>
        <tr>
            <td><?php echo htmlspecialchars($user->first_name,ENT_QUOTES,'UTF-8');?></td>
            <td><?php echo htmlspecialchars($user->last_name,ENT_QUOTES,'UTF-8');?></td>
            <td><?php echo htmlspecialchars($user->email,ENT_QUOTES,'UTF-8');?></td>
            <td>
        <?php foreach ($user->groups as $group):?>
            <?php echo anchor("auth/edit_group/".$group->id, htmlspecialchars($group->name,ENT_QUOTES,'UTF-8')) ;?><br />
                <?php endforeach?>
            </td>
                        <td><?php echo htmlspecialchars($user->codigo,ENT_QUOTES,'UTF-8');?></td>
            <td><?php echo ($user->active) ? anchor("auth/deactivate/".$user->id, lang('index_active_link')) : anchor("auth/activate/". $user->id, lang('index_inactive_link'));?></td>
            <td><?php echo anchor("auth/edit_user/".$user->id, 'Edit') ;?></td>
                        <td><?php echo htmlspecialchars($user->red,ENT_QUOTES,'UTF-8');?></td>
        </tr>
    <?php endforeach;?>
                                </tbody>
<tfoot>
<tr>
<th><?php echo lang('index_fname_th');?></th>
        <th><?php echo lang('index_lname_th');?></th>
        <th><?php echo lang('index_email_th');?></th>
        <th><?php echo lang('index_groups_th');?></th>
                <th><?php echo lang('index_code_th');?></th>
        <th><?php echo lang('index_status_th');?></th>
        <th><?php echo lang('index_action_th');?></th>
                <th><?php echo lang('index_net_th');?></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>

<div class="widget-foot">

</div>

</div>

edit:

this is my js script:

/* Data Table */
/* ********** */

$(document).ready(function() {
    $('#data-table').dataTable({
       "sPaginationType": "full_numbers",
         "dom": 'T<"clear">lfrtip'
    });
});

/* ****************************** */

and my css is the big file you download from datatables web page.

I have spent almost a week trying to add tabletools to my code i just cant understand the documentation, can anyone point me in the right direction please.

Thanks everyone!

Upvotes: 0

Views: 485

Answers (3)

IOS Singh
IOS Singh

Reputation: 617

first import the data tabletools package after that unzipped the folder where the your project folder after that include the source file like this

<script src="http://localhost:88/project_name/DataTables-1.10.7/media/js/jquery.js"></script>
<script src="http://localhost:88/project_name/DataTables-1.10.7/media/js/jquery.dataTables.js"></script>
<script src="http://localhost:88/project_name/DataTables-1.10.7/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
<link href="http://localhost:88/project_name/DataTables-1.10.7/media/css/jquery.dataTables.css"rel="stylesheet">
<link href="http://localhost:88/project_name/DataTables-1.10.7/extensions/TableTools/css/dataTables.tableTools.css"rel="stylesheet">

and after that include the jquery function

<script>
$(document).ready(function() {
$('#index1').DataTable( {
dom: 'T<"clear">lfrtip',
tableTools: {
        "sSwfPath": "http://localhost:88/project_name/DataTables1.10.7/extensions/TableTools/swf/copy_csv_xls.swf"
    }
} );

} );
</script>

here index1 is table id

Upvotes: 1

sergiodebcn
sergiodebcn

Reputation: 310

Add tabletools swf file to your datatable options, and add the datatables js and css files to your code

$('#status_table').DataTable({
    "tableTools": {
        "sSwfPath": "packages/datatables-tabletools/swf/copy_csv_xls_pdf.swf"
    }
});

Upvotes: 0

Jobst
Jobst

Reputation: 559

Ok.

Table tools are a PLUGIN to datatables, a number of steps are required to get this to work.

I cannot see your header, so I do not know what you have included (js,css)

First you need to have all the scripts/css for the standard data tables.

In addition to that you need to go https://www.datatables.net/extensions/tabletools/plug-ins and download/save the javascript and add that to your header to be loaded, you also need to download, save and load the table tools css sheet in your header as well - again I cannot see that you have done so.

Go to https://www.datatables.net/release-datatables/extensions/TableTools/examples/simple.html, save all the HTML/JS/CSS locally and create a file to test that locally. Once that is working with external files start including the files (js/css) on your server - if its still working you know you have all the required libraries.

Then try your code - if it does not work put a SIMPLE table in their - you could even use the one from the table tools site.

If its still not working what does the debugging console tell you (Firefox/Chrome)?

Upvotes: 0

Related Questions