How to add multiple datatables in one page

Hello,

How to add multiple datatables in one page

window.addEventListener('DOMContentLoaded', event => {

    // Simple-DataTables

    // https://github.com/fiduswriter/Simple-DataTables/wiki

    const datatablesSimple = document.getElementById('datatablesSimple');

    if (datatablesSimple) {

        new simpleDatatables.DataTable(datatablesSimple);

    }

});

Thank you

What is a ‘datatable’? *(you provided zero links)

Either way… my guess would be to create a new constant and reference that new instance.

1 Like

I am using this example admin panel
I need to use two different content tables on one page

https://startbootstrap.com/previews/sb-admin

@whispers is right, I would do the same thing. Create a new table with a new ID like my_new_table and then add another instance inside your event listener…

    const my_new_table = document.getElementById('my_new_table');

    if (my_new_table) {

        new simpleDatatables.DataTable(my_new_table);

    }

There’s probably a more concise way to do it but this would be my first thoughts

Thank you for the answer
Like below?

window.addEventListener('DOMContentLoaded', event => {

    // Simple-DataTables

    // https://github.com/fiduswriter/Simple-DataTables/wiki

    const datatablesSimple = document.getElementById('datatablesSimple');

    if (datatablesSimple) {

        new simpleDatatables.DataTable(datatablesSimple);

    }
	
    const my_new_table = document.getElementById('my_new_table');

    if (my_new_table) {

        new simpleDatatables.DataTable(my_new_table);

    }
	
});

Hello,

How to add “Show 5,10,15,20,25 entries per page” options?
Example: How to make “5,10,15,20,25,50,100,All”?

I can’t get results as suggested by datatable on its site. Do I need to do something different in the above script?

Get all data back as an array, and loop through/display as you want.

I solved the problem as below
Also, how do I sort in the first column by default?

It says here, I guess I didn’t quite understand

<script>
window.addEventListener('DOMContentLoaded', event => {
    // Simple-DataTables
    // https://github.com/fiduswriter/Simple-DataTables/wiki

    const malzemetablo = document.getElementById('malzemetablo');
    if (malzemetablo) {
        new simpleDatatables.DataTable(malzemetablo, { 
            perPageSelect: [10, 25, 50, 100,250,500,1000],
            labels: {
                placeholder: 'Ara..'},
            perPage: 1000,
        });
    }
});
</script>
Sponsor our Newsletter | Privacy Policy | Terms of Service