Way to set aLengthMenu dynamically

Way to set aLengthMenu dynamically

snkarthicksnkarthick Posts: 4Questions: 0Answers: 0
edited August 2012 in General
Hi,
Is there a way to set/update the aLengthMenu property dynamically.
The table we are working on, would have to dynamically resize and show the number of rows according to the height of the container.
This we do it using the iDisplayLength property. We initialise this parameter to the initial value and whenever the user resizes the container, we calculate the number of rows and set the iDisplayLength property in a dynamic way and it works fine.
In the similar fashion, we also want to set the aLengthMenu to display the calculated number of rows on top of the dropdown along with the other options for the user to choose. I am using the dataTable.fnSettings() method call and set the aLengthMenu property to set the values for the dropdown dynamically.
But the dropdown values are not getting updated. It remains in the initial values it was set.

Is it how it works. Or is there a way to update the dropdown values dynamically?

Thanks,
Karthick

Replies

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    > I am using the dataTable.fnSettings() method call and set the aLengthMenu

    No - the settings object is an internal settings store and should not be access externally unless you are very certain you understand what the DataTables code will do with the changed setting. At best it will ignore it (this case), at worse it will cause the table to behave very erratically.

    There currently is no API to change the options in the length menu - however, in this particular case you can simply change it using standard DOM / jQuery methods (i.e. new Option() etc) since DataTables doesn't really care what the values are.

    Allan
  • snkarthicksnkarthick Posts: 4Questions: 0Answers: 0
    Hi Allan,
    Thanks for your reply.
    Can you kindly elaborate how do i do this with DOM/jQuery methods.
    I am little confused as to how to do this.

    Thanks again,
    Karthick
  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin
    See for example: http://www.javascriptkit.com/jsref/select.shtml

    Allan
This discussion has been closed.