Different Tables From Different DB Tables On A Single Page

Different Tables From Different DB Tables On A Single Page

mankramomankramo Posts: 24Questions: 5Answers: 0

Hello guys, please forgive me if this question has been asked already in other form. I looked through the questions but couldnt find a similar one.

I want to build two different tables on a single page but each of these two tables will be populated with data coming from separate DB tables. I have created separate php files to handle data into and out of each tablle and i have two different tables on the HTML file each with a uniqiue id property. My problem now is with the js file. i cant just get my head around it.
This is what i have on the js file:

************************************************CODE BEGINS************************************************************
(function($){

$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'assets/datatable_assets/php/table.nestor_exchangerates.php',
table: '#nestor_exchangerates',
fields: [
{
"label": "Currency:",
"name": "exchangerate_currency"
},
{
"label": "Date:",
"name": "exchangerate_date",
"type": "datetime",
"format": "YYYY-MM-DD HH:mm:ss"
},
{
"label": "Amount:",
"name": "exchangerate_amount"
}
]
} );

var table = $('#nestor_exchangerates').DataTable( {
    dom: 'Bfrtip',
    ajax: 'assets/datatable_assets/php/table.nestor_exchangerates.php',
    columns: [
        {
            "data": "exchangerate_currency"
        },
        {
            "data": "exchangerate_date"
        },
        {
            "data": "exchangerate_amount"
        }
    ],
    select: true,
    lengthChange: false,
    buttons: [
        { extend: 'create', editor: editor },
        { extend: 'edit',   editor: editor },
        { extend: 'remove', editor: editor }
    ]
} );

} );

}(jQuery));

******************************************************* END CODE**************************************************************

but it doesnt work. Please help.

Thank you.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    edited January 2018 Answer ✓

    Here is an example of two Datatables:
    https://datatables.net/examples/basic_init/multiple_tables.html

    You can create you second set of Datatables and Editor with different variables:

    var editor  <<<change to editor2 or a name of your choice
    var table  <<<change to table2 or a name of your choice
    

    Use something different for the second set and make sure to use the correct variables for the buttons, etc:

        buttons: [
            { extend: 'create', editor: editor },  <<<change editor: editor to editor: editor2 or whatever you use
            { extend: 'edit',   editor: editor },
            { extend: 'remove', editor: editor }
        ]
    

    Does this help answer your questions?

    Kevin

  • mankramomankramo Posts: 24Questions: 5Answers: 0

    thank you very much @kthorngren :)

This discussion has been closed.