How update tr data attribute on other page

How update tr data attribute on other page

amboambo Posts: 4Questions: 0Answers: 0

Hi all :) !

I need update all <tr> attribute data-id on my big table dinamically.
next code work only on the current page:

mainTable.row(index).node().getAttribute('data-id') - i get data if i have index on current page, because it's node().

Help me, how i can get(set) date on other page?

Replies

  • allanallan Posts: 63,214Questions: 1Answers: 10,415 Site admin

    rows() will let you select rows for all pages.

    If that doesn't help, can you link to an example of what you mean, as I'm not 100% sure I understand.

    Allan

  • amboambo Posts: 4Questions: 0Answers: 0
    edited January 2021

    rows() will get only records of current page... I wanna get all nodes, for all pages.

    <tr data-id="123"><td>...</td></tr>
    <tr data-id="323"><td>...</td></tr>
    ...
    <tr data-id="623"><td>...</td></tr>

    I must change all "data" attribute for all records (on the all pages)

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    You can restrict rows() to return rows for the current page, by default it returns rows for all pages - not just the current page.

    Colin

  • amboambo Posts: 4Questions: 0Answers: 0

    Thanks!
    But how i get all <tr> data-attribute (not for current page)?
    If row(index).node() to return element only for the current page.

    As example, i want change data-id attribute for row with index=25 (that is on page number 3), current page has number 1.
    row(index).node().getAttribute('id') - cannot find this element (logic :) )

    row(index).node().getAttribute('id'), if index = 3 on the page=1, found it :)

    I need change data-id if current page is 1 but element is on 3 page.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    You can get them all with rows().node() - note you are using row(), not rows(),

    Colin

  • amboambo Posts: 4Questions: 0Answers: 0

    Thnx.
    But i wanna get data from not current page.
    rows().nodes() - get all dom-element from current page.
    My table consist data-attribute into <tr> tags.
    And i need change this.
    Is has DataTable other api for change data-attribute parameters?

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    rows().nodes() - get all dom-element from current page.

    Are you using server side processing or deferRender? If so that is why.

    This example shows that rows().nodes() works with all the rendered data in the client:
    http://live.datatables.net/nozugame/1/edit

    Kevin

  • kthorngrenkthorngren Posts: 21,174Questions: 26Answers: 4,923

    Another option might be to use createdRow to update the data attributes.

    As Colin mentioned the best way for us to help is to provide a test case showing what you have and what you are trying to do.

    Kevin

This discussion has been closed.