0
votes

I am trying to show only the first N rows of data on DataTables, but can't find a way.

Additionally, when I click the Copy or Excel buttons I want to download all the data, and not just the rows who are being show.

In my last try, I used paging and pageLength without success. Below is the code. My data is on tbldata:

var dtable = $("#dvTableAC").DataTable({
    data: tbldata,
    columns: [
        { title: "A" },
        { title: "B" },
        { title: "C" },
        { title: "D" }
    ],
    "paging": false,
    "pageLength": 50,
    dom: 'Blfrtip',
    buttons: [
        'excel', 'copy'
    ]
});
1

1 Answers

0
votes

Please not that you need an extra plugin to be able to use the buttons (excel, copy). https://datatables.net/extensions/buttons/built-in

var dtable = $("#dvTableAC").DataTable({
    data: tbldata,
    columns: [
        { title: "A" },
        { title: "B" },
        { title: "C" },
        { title: "D" }
    ],
    "paging": true,
    "pageLenght":10,
    dom: 'Blfrtip',
    buttons: [
        'excel', 'copy'
    ]
});

Datatables will show all the data you send to it, if you set paging to false, then pageLenght is not used. If you want to limit the total records that datatables show, you must send just those records to it. You can restrict the number on the mysql query using limit 10. But I don't know any method of not having pagination and show only a x amount of rows from the total.