getElementById with information in next pages

getElementById with information in next pages

magicratmagicrat Posts: 3Questions: 0Answers: 0
edited August 2011 in General
Hi

I'm new here, so maybe this a newbie mistake.

I need to be able to get all the data even if due to pagination or filter it is not actually shown in the table.
I use document.getElementById, but it doesn't access non visible elements.

Example: I have 17 rows and show 1-10, the other 7 are in page 2.
Problem: document.getElementById cannot access the ids of those 7 elements in page 2.

Is there a way to solve that problem?
Shall I simply disable pagination and filtering?
Shall I use something different than getElementById? If so, what would that be?

I'll give you some more info about my page in case it may be useful:
- I used the data table to set permissions to users.
- To do so I have a php page that reads data from and XML file and populates a table with the possible permissions, the users and the permissions every user has.
- Every permission is reflected with a checkbutton to indicate whether the user has the permission or not.
- Permissions can be changed by checking/unchecking the checkbuttons
- Below the table there's a button that allows for the changes to be saved.
- When I press the button I call a javascript function that gets the data (via document.getElementById), serializes it and passes it to another php page. That page simply saves the file and redirects the user to the 1st page, so that the XML file is saved and the user is still on the permissions page.

Thanks in advance.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > I use document.getElementById, but it doesn't access non visible elements.

    Correct - the non-visible elements are not in the document in order to speed things up. Thus this kind of selector won't work.

    What you need to do is use the API method fnGetNodes() to get an array of all TR elements and do:

    [code]
    $('#id', oTable.fnGetNodes())...
    [/code]

    Allan
  • magicratmagicrat Posts: 3Questions: 0Answers: 0
    Thanks for your tip Allan.

    Just one question: what does "$('#id', oTable.fnGetNodes())" return?

    With document.getElementById I obtained directly the checkbox I wanted as an [object HTMLInputElement]. That way I could directly access the name property to get some info and know whether it was checked or not.
    With this new method I get an [object Object] that doesn't have those properties.

    How do I get the html object?

    Thanks.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    It returns a jQuery object, as you would expect from the $() function. If you want the HTML node, just use $()[0] (to get the first matched element).

    Allan
This discussion has been closed.