Paging loses pagelength value

Paging loses pagelength value

ddfiggekddfiggek Posts: 4Questions: 1Answers: 0
edited June 2014 in Free community support

Hi,

I've just finished putting together my first datatables project and am now testing it, but have noticed that whenever I click the Page 2 button, the number of rows per page changes from 25 to all the rows in the table (about 4,000).

I can't give any link to the website, because it's on my machine, but below are the table settings I've used to set up the datatable:

<table id="results">
    <thead>
    <tr>
        <th id="investorRef" class="dtlcol">Investor Ref</th>
        <th id="productName">Product Name</th>
        <th id="intRate">Interest Rate</th>
        <th id="startDate" class="dtlcol txt-center">Product Start Date</th>
        <th id="endDate" class="dtlcol txt-center">Product End Date</th>
        <th id="intPaid" class="txt-center">Interest Paid For Period</th>
        <th id="intAccrued" class="txt-center">Interest Accrued For Period</th>
        <th id="intPaidYTD" class="txt-center">Interest Paid YTD<br />(<?php echo $strYtdPeriod; ?>)</th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>
oTable =
$("#results").DataTable({"pagingType"   : "full_numbers"
                        ,"pageLength"   : "25"
                        ,"dom"          : '<"top">lrt<"bottom"ip><"clear">'
                        ,"ajax"         : "ajax/p2pReports.php?action=getInterestAccruals&showdetail="+$("#showdetail").prop("checked")
                        ,"columns"      : [{"data": "InvestorRef"}
                                          ,{"data": "ProductName"}
                                          ,{"data": "IntRate"}
                                          ,{"data": "StartDate"}
                                          ,{"data": "EndDate"}
                                          ,{"data": "IntPaid"}
                                          ,{"data": "IntAccrued"}
                                          ,{"data": "IntPaidYTD"}
                                          ]
                        });

if  ($("#showdetail").prop("checked")) {
    oTable.columns(".dtlcol").visible(true);
} else {
    oTable.columns(".dtlcol").visible(false);
}

The way it works is that the table is first displayed with the showdetail checkbox unchecked, which causes the if to hide the InvestorRef, StartDate and EndDate columns by setting all columns with a class of dtlcol to hidden. There are only about 20 records and there isn't a problem at this point.

However, when the checkbox is checked, the 3 columns are unhidden and the table refreshed with the 4,000+ rows, paged at 25 rows per page. The first page displays correctly, but when I click the page 2 button, this is when the paging goes a bit strange and displays all of the rows, instead of the second 25 and positions the table with the 26th record at the top of the screen.

This problem happens on all the rows per page options, not just the 25 one.

Can anyone tell me what could be wrong and how to fix it e.g. I've specified the wrong settings or missed one or more that would make the paging work properly?

Debbie

Answers

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14

    Best guess is that the pageLength is being set to -1 when you page for some reason, but it's pretty much impossible to tell from what you've given. Try running the table, going to the second page and than using the debugger (http://debug.datatables.net/) to link the information that would be needed to really look into the issue.

  • ddfiggekddfiggek Posts: 4Questions: 1Answers: 0
    edited June 2014

    Oh, that's useful. I hadn't spotted the debugger yet.

    I've spotted another anomaly now, so I've uploaded two records:

    1 - irarun - the problem with this one is that, even though the pagelength has been set to 10 in the table initialisation, after the initial page load, when I click the Page 2 button, all the rows are shown, instead of the second set of 10.

    The strange thing is, that, if I use the Show Entries drop down to select a different number of rows per page, the problem seems to be corrected i.e. just the required numbers of rows per page are shown, no matter which page number I click on.

    i.e. the problem only seems to occur on the initial page load, rather than when the Show Entries drop down is used.

    This problem occurs when all the columns are shown.

    2 - etudat - the Next button doesn't work when I'm on the first page. All the other buttons do work.

    This problem occurs when the 3 columns mentioned in the initial post are hidden.

    Again, the problem seems to only occur after the initial page load and be corrected when I use the Show Entries drop down to select a different number of rows per page.

    I've looked at the logs, but I don't really know what I'm looking for, so any help in interpreting them to find what the problem could be would be gratefully received.

    If you need any other information to help me find the problem and solution, please let me know what you need.

    Debbie

  • ddfiggekddfiggek Posts: 4Questions: 1Answers: 0

    Can anyone tell me how to interpret the debugger logs?

    Debbie

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    Might be the problem, might not be, but:

    "pageLength": "10",

    is very certainly wrong. You are giving it a string there - it should be an integer. See pageLength.

    Allan

  • ddfiggekddfiggek Posts: 4Questions: 1Answers: 0

    Hi Allan,

    Yes, that was it. It's always the small things that escape you, isn't it? :-)

    So am I right in thinking that goes for all the other options that take numbers?

    Debbie

  • RpiechuraRpiechura Posts: 98Questions: 3Answers: 14
    edited June 2014

    Yes, all numbers need to be integers and not strings, some of them have different options / behaviors if you give them strings but chances are that you'll want to use integers.

    Sorry about not getting back to you, had a deadline to do something else so I was busy. Glad @allan caught that though because I sure wouldn't have.

This discussion has been closed.