changing iDisplayLength with the api?

changing iDisplayLength with the api?

webguruwebguru Posts: 16Questions: 0Answers: 0
edited February 2011 in General
Is there a way to reproduce the pagination select box externally through the api? I basically want a button elsewhere on the page that when clicked would change the pagination amount

Replies

  • jamillerjamiller Posts: 27Questions: 0Answers: 0
    Have you tried this?
    [code]
    var oTable = $('#someTable').dataTable();
    var oSettings = oTable.fnSettings();
    // Change iDisplayLength
    oSettings._iDisplayLength = 9; // or whatever number you want here
    [/code]
  • webguruwebguru Posts: 16Questions: 0Answers: 0
    That doesn't seem to work... unless Im missing something
  • jamillerjamiller Posts: 27Questions: 0Answers: 0
    Take a look at this: http://jsfiddle.net/tWAcm/2/
  • jamillerjamiller Posts: 27Questions: 0Answers: 0
    The key may have been the oTable.fnDraw() after setting iDisplayLength
  • webguruwebguru Posts: 16Questions: 0Answers: 0
    Yeah that did the trick. Thanks!
  • webguruwebguru Posts: 16Questions: 0Answers: 0
    Im not seeing any specific documentation referring to how this works:

    oSettings._iDisplayLength = 9;

    When I try passing other settings with that format they don't seem to work. What is the methodology of changing other table settings in this way?
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    There isn't any - oSettings in an internal data store that DataTables uses for storing information about the table and its state. It isn't documented and is possible that aspects of it may change between releases. As such, typically it should be avoided unless you know what you are doing with it :-). Plug-in API functions can be used such as fnLengthChange ( http://datatables.net/plug-ins/api#fnLengthChange ) which will deal with the state update (I try to keep all plug-in API methods up-to-date with the current state of DataTables - although in fairness the settings object properties don't change much!).

    Allan
This discussion has been closed.