Dadabik and Data Tables

deep64blue

Well-known member
I'm trying to integrate Data Tables into DaDABIK and wonder if it is compatible?

I have added the following to header.php:-

[pre]

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.21/js/jquery.dataTables.js"></script>
[/pre]

I created the following custom PHP page

[pre]
<?php
// don't delete this line, this must be the first line of your code
if(!defined('custom_page_from_inclusion')) { die(); }
require_once('error_handler.php');
require_once('myfunctions.php');

echo "<table id='example' class='display' style='width: 100%;'>";
echo "<thead>";
echo "<tr>";
echo "<th>Name</th>";
echo "<th>Position</th>";
echo "<th>Office</th>";
echo "<th>Age</th>";
echo "<th>Start date</th>";
echo "<th>Salary</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
echo "<tr>";
echo "<td>Tiger Nixon</td>";
echo "<td>System Architect</td>";
echo "<td>Edinburgh</td>";
echo "<td>61</td>";
echo "<td>2011/04/25</td>";
echo "<td>$320,800</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Garrett Winters</td>";
echo "<td>Accountant</td>";
echo "<td>Tokyo</td>";
echo "<td>63</td>";
echo "<td>2011/07/25</td>";
echo "<td>$170,750</td>";
echo "</tr>";
echo "</tbody>";
echo "<tfoot>";
echo "<tr>";
echo "<th>Name</th>";
echo "<th>Position</th>";
echo "<th>Office</th>";
echo "<th>Age</th>";
echo "<th>Start date</th>";
echo "<th>Salary</th>";
echo "</tr>";
echo "</tfoot>";
echo "</table>";
echo "<p><br /><br /></p>";
echo "<script>";
echo "$(document).ready( function () {";
echo "$('#myTable').DataTable();";
echo "} );";
echo "</script>";

?>
[/pre]

A table is displayed but it is unformatted with none of the datatables features or formatting.

dadabik said:
Your current DaDaBIK version
You are using DaDaBIK version 10.2-Manarola enterprise, installed on Jul 16, 2020 (installation code: 157345f10b431e712d), the latest version of DaDaBIK is 10.2-Manarola released on Jul 15, 2020

You are runnning the last release of DaDaBIK

In case you want to upgrade to a more powerful edition (from Pro to Enterprise/Platinum, from Enteprise to Platinum) please contact us.

System info
PHP Version: 7.3.19

mysql version: 5.5.5-10.4.13-MariaDB

Web server: Apache/2.4.43 (Unix) OpenSSL/1.1.1g PHP/7.3.19 mod_perl/2.0.11 Perl/v5.30.3

Client: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36
 

deep64blue

Well-known member
It's been a long time but I'm working on another project that would benefit from datatables, is it possible to use these with Dadabik?

Alternatively can l call the dadabik table generator directly - I'm looking to take advantage of pagination etc.
 

eugenio

Administrator
Staff member
Hi,
I think that at the moment the two approaches (especially on the pagination) are too different to mix them.
Which Data Tables features do you miss the most in DaDaBIK?
 

deep64blue

Well-known member
I want to be able to have tables with pagination, choose number of items etc in a custom page i.e. not based on a MySQL Table.
 

deep64blue

Well-known member
To give an example - we have a custom page where once the user has selected the difficulty level then we calculate various stats and show them in a table. I wanted to use DataTables to have the table paginated etc.

An alternative approach would be if there was a Dadabik function I could pass the array of the table contents to and have Dadabik produce a table.
 

eugenio

Administrator
Staff member
Ok, I understand, I missed the fact you are using custom pages.
It should work, but probably there are some conflicts between DaDaBIK CSS and Data tables CSS.

At the moment there isn't a "clean" way to produce the dadabik results grid from a custom page. You can call build_results_table() and you can see the code of the function in /views/results_grid.php but I guess it's not that easy to use.

A specific API for building a results grid in a custom page starting from custom data would probably be useful.
There is already a feature request here:
but it's a bit generic.
 

deep64blue

Well-known member
You can call build_results_table() and you can see the code of the function in /views/results_grid.php but I guess it's not that easy to use.
I saw that function but as it has a parameter $table_name I assumed it relied on a an underlying table rather than a query.

EDIT: Just realised it could also mean the name of the table you are building!!
 
Last edited:

eugenio

Administrator
Staff member
Hi,
the main input is $res_records, that is a recordset, but anyway I think it would be very hard to use the function for a generic dataset as in your case.

The only solution would be a clean API that stays as a layer on the top of build_results_table but it requires quite a lot of work and considering that probably it would be used just by a fraction of the users, I don't think it will be developed anytime soon unless someone sponsors it.
 

deep64blue

Well-known member
It's not as powerful as DataTables but I found a JS library for pagination, in case anyone else wants to use it here are the instructions.

I downloaded the js files and put them in a folder under my custom PHP files and added this to include/header/php:-

<script src="include/custom_php_files/js/paginationTable.js"></script>

I downloaded the css and added it to css/styles_screen_custom.css.

To invoke the pagination on a table with an id of 'civ' I added this at the end of my custom PHP file:-

?>
<script>
Paginator.init({
tableID: "civ",
rows: 10,
navStyle: 'custom',
});
</script>
<?php
 
Top