'live' update of values changes focus

'live' update of values changes focus

vtgavvtgav Posts: 5Questions: 3Answers: 0

I have a table where I automatically update values based on 'live' data coming in through a websocket.

The table has around 60 rows and currently shows 10 rows per tabbed 'page'.

The scenario is I'm viewing the 3rd page of the table ( for example ), and some new live data arrives on the websocket for something on the 1st page. So my code updates the value in the table but then table view automatically changes to show the first page which isn't very good for the user who was happily viewing the 3rd page ( if that description makes any sense ! ).

the code fragment hanging off the websocket is :-

                // update the value of the DB point which has an id = 'payloadObj.pointid' 
                // the new value will be set to 'payloadObj.value'

                case "dbpointupdate":

                    var dbnewtable = $('#dbnewtable').DataTable();

                    var myID = "#" + payloadObj.pointid;  // generate the ID for the row which needs to be modified
                    var rowNode0 = dbnewtable.row(myID);
                    var rowData = dbnewtable.row( rowNode0 ).data();
                    rowData[4] = payloadObj.value;  // update with new live value
                    dbnewtable
                        .row( rowNode0 )
                        .data( rowData )
                        .draw();
                break;

I guess something I'm doing is changing focus ? so the table view changes to the page with the focused row ?
Is it the search for the row with an ID that does this ?

                    var rowNode0 = dbnewtable.row(myID);

If that is the case, is there some alternative code which won't change the focus ?

I'm new to using Datatables so I'm probably being stupid !

Gav

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @vtgav ,

    If you pass false or page into draw() on line 15, it will maintain the position in the table.

    Cheers,

    Colin

  • vtgavvtgav Posts: 5Questions: 3Answers: 0

    thats great - thanks, worked !

This discussion has been closed.