Custom display length problem

Custom display length problem

virgilvirgil Posts: 12Questions: 0Answers: 0
edited September 2011 in DataTables 1.8
Hi,

I'm trying to use my own custom display length changer, and I got to this:

[code]
$('#change_iDisplayLength').click( function() {
if ($('#iDisplayLength').val() != display_length) {
display_length = $('#iDisplayLength').val();
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = $('#iDisplayLength').val();
oTable.fnPageChange("first");
//oTable.fnDraw();
}
});
[/code]

Now this work great if I get my data dynamically but not if I have my data already in the table from the beginning
For example, I have 16 entries that I return from the start and 10 entries per page set by default, now if I change to 5 entries per page it takes me to the first page and I have 5 entries on it, from 1 to 5, but then on the second page I have entries from 6 to 16, on third from 10 to 16 and on fourth entry 16 again. I don't get what I'm doing wrong, especially that this works great if I get the entries dynamically for every page. I tried calling fnDraw but that didn't help either.

Any ideea about what I might be doing wrong?

Thanks,
Virgil

Replies

  • virgilvirgil Posts: 12Questions: 0Answers: 0
    The elements are not in the html directly, I send them from django into the template like this:

    [code]

    {% if not dynamic %}
    {% for invoice in invoices %}




    ...

    {% endfor %}
    {% endif %}

    [/code]


    If I copy the output into the html template directly it works great. Any idea about why this could be?
  • virgilvirgil Posts: 12Questions: 0Answers: 0
    I was wrong, even if I copy them (but all 16 of them) in the html directly the problem still appears if I set display length less than 7.
    So I guess the problem is caused by the datatable. Any idea why this could be?
  • virgilvirgil Posts: 12Questions: 0Answers: 0
    I finally fixed it after putting "iDisplayLength": 10, in the definition of the datatable and changing oSettings._iDisplayLength = $('#iDisplayLength').val(); to oSettings._iDisplayLength = parseInt($('#iDisplayLength').val());

    Thanks
This discussion has been closed.