how to get it to the entire table

how to get it to the entire table

totututototututo Posts: 4Questions: 1Answers: 0
edited September 27 in Free community support

Link to test case: https://live.datatables.net/jemogewe/1/edit

Debugger code (debug.datatables.net):
Error messages shown:

Description of problem: I don't know how to get the html via prepend method to apply to the entire table.

It is working but applies to the first page only.

But looking to apply the result to the entire table.

Anyone may help me ?

Answers

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin
    $("tr:odd td:nth-of-type(1)").prepend("Some prepended text. ");
    

    only gets the elements that are on the page at the time. Use the DataTables API to get all rows. For example table.rows().nodes() will get all nodes across all pages (note that if you are Ajax loading, which your example isn't, then deferRender would need to be disabled for that to work).

    Also I would very strongly discourage you from using jQuery or DOM methods to update the table's data. Use the DataTables API again, otherwise it won't know that you've changed the data.

    Allan

  • totututototututo Posts: 4Questions: 1Answers: 0

    Now at https://live.datatables.net/jemogewe/1/edit

    works fine.

    script is

    var table = new DataTable('#example');

    table.on('draw', function () {

    var _clicked = false;

    if(!_clicked){
    _clicked = true;

    $("tr:odd td:nth-of-type(1)").prepend("Some prepended text. ");
    }

    });

    var _clicked = false;
    $('p').click(function(){

    if(!_clicked){
    _clicked = true;

    $("tr:odd td:nth-of-type(1)").prepend("Some prepended text. ");
    }
    })

    but if click the next button repeated then the prepend data again added.

    how to stop adding again to the exists ?

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    You would need to check the row to see if you have already prepended the data or not. You could perhaps set a flag on the tr for the row and then check that flag.

    Allan

  • totututototututo Posts: 4Questions: 1Answers: 0
    edited September 30

    okay. i will try it.

    in the meantime

    can you show me how to program three html buttons

    1) first (if clicks move to the first page of the table)

    2) middle (move to the middles page of the total pages)

    3) last (move to last page)

    to do pagination.

    https://live.datatables.net/rolinojo/1/edit

    create the test case wiith buttons there.

    but don't know the parameters and sequences.

    welome all possible helps from all.

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    First and last are trivial - use page() with first or last:

    table.page('first').draw(false);
    

    For the middle of the table, you need to workaround where the middle is, using page.info().

    Your example updated: https://live.datatables.net/hobuhipo/1/edit .

    Allan

  • totututototututo Posts: 4Questions: 1Answers: 0

    cheers.

    i am strugling with the previuos query.

    if it is not so time consuming for you, then can you show a solution ?

  • allanallan Posts: 63,290Questions: 1Answers: 10,428 Site admin

    I thought I had? My example shows the three things you asked for.

    Allan

Sign In or Register to comment.