how to change the show entries

how to change the show entries

limadolimado Posts: 1Questions: 1Answers: 0

Hello I am working on a Project, where I want to change the Shown entries.

First of all my Table starts with 10 shown entries, but I want to change it into 0 -100, because I don’t want the table to be seen from the beginning, I want an option where I can change it from 0 for example in to 10.

I used this CDN:

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.18/b-1.5.4/b-html5-1.5.4/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.18/b-1.5.4/b-html5-1.5.4/datatables.min.js"></script>

$(document).ready( function () {
$('#table_id').DataTable();

} );

Can someone help be out?

Or is there an Option to hide the table and let it been shown later per click?

Answers

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    edited December 2018

    https://datatables.net/reference/option/pageLength

    and

    https://datatables.net/reference/option/lengthMenu

    like in here:

    var yourTable= $('#tblContract').DataTable({
        dom: "Bfrltip",
        ajax: {
            url: '.....'
        },
        pageLength: 0,
        lengthMenu: [0, 5, 10, 20, 50, 100, 200, 500],
        columns: [.....
    
  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954
    edited December 2018

    Here are a few options you can look at:

    1. You can put the Datatable inside a hidden div then on clicking a button or whatever you can show the div. Maybe ue jQuery hide() and show() methods for this.
    2. You could use tabs to hide the Datatable.
    3. You can start with a blank Datatable. Don't use ajax or data to load the data. Then on a button click use jQuery's ajax method to fetch the data and use rows.add() to populate the Datatable.

    Kevin

This discussion has been closed.