Select created row using serverside

Select created row using serverside

TronikTronik Posts: 120Questions: 27Answers: 1

Hi,

I want the created row to get selected after creation.

editor.on('postCreate', function (e, json, data, id) {
            console.log(id)
            table.row('#row_' + id).select();
        });

This works with serverside false. Is there a way to get it work with serverside true?
The row id is printed in console but not selected.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin
    Answer ✓

    With server-side processing you need to wait for the next draw event:

    editor.on('postCreate', function (e, json, data, id) {
      table.one('draw', function () {
        table.row('#row_' + id).select();
      });
    });
    

    The reason for that is that the row isn't in the table or document until the draw happens which is async with server-side processing enabled.

    Allan

  • TronikTronik Posts: 120Questions: 27Answers: 1

    Wonderful, thanks!

  • TronikTronik Posts: 120Questions: 27Answers: 1
    edited October 2021

    One more thing I need to check with you regarding this,

    Everything works with the above code except when using scroller plugin, and the user has scrolled down enough to make datatables fetch another "page" of data.
    If the user at that stage press NEW the selected row will not get selected after submitted.

    I guess a conflict occurs with the draw events. Do you have any suggestions on how to tackle that?

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    It won't get selected because it doesn't exist on the client-side (it is outside of the paging). What makes this particularly difficult is that we don't know where in the paging the new row will appear since it is user data based and the sorting presumably can put it anywhere. Another call to the server would be needed to determine the paging position - redraw the table to that position (which with SSP is another call to the server) and then select it.

    I don't see an easy way to address this I'm afraid.

    Allan

  • TronikTronik Posts: 120Questions: 27Answers: 1

    Ok, I understand, thank you

Sign In or Register to comment.