How to ping for changes, and adjust row bgcolor accordingly

How to ping for changes, and adjust row bgcolor accordingly

philipphilip Posts: 11Questions: 5Answers: 0

I'd like to ping/poll the data source that fills the table and look for changes, and then alter row colors based on what changed (but not refresh the data contents). For example, changing a row color to green might mean "Hey, someone else changed field foo in this row."

I'm not sure where to start, and am looking for pointers. I'm moving from server-side programming to client-side so am still learning JS.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,920Questions: 1Answers: 10,152 Site admin
    Answer ✓

    There are a lot of ways to do this. When you ping the server will it give you only the changed rows for example? Or do you need to do the comparison on the client-side? Assuming the former you would use the row() selector to get the row in question (assuming you have a way to select it - an id / primary key value would be the typical way) and then update it (row().data()) and add a class for the colouring (row().node() with some jQuery $().addClass()) for example.

    If you have to do the comparison, you'll need a loop, which will of course be a good deal slower.

    Allan

  • philipphilip Posts: 11Questions: 5Answers: 0

    Thanks! Because I'm a server-side programmer, I assumed I'd pass all datatables data to a (in this case, PHP) script, query the database again and compare the two (server-side), then report back what changed, and then finally update the row colors. Is this, essentially, what you're saying? Originally all data is passed in via "ajax":"url".

  • allanallan Posts: 61,920Questions: 1Answers: 10,152 Site admin

    Yes - that is absolutely one option (the first of the two I mentioned). Basically it means that the comparison is done at the server-side. If you are most comfortable with that, then that's the way to go!

    Allan

This discussion has been closed.