How to prevent row to be re-rendered when user selects the row?

How to prevent row to be re-rendered when user selects the row?

yusrilyusril Posts: 14Questions: 10Answers: 0
edited May 2017 in Free community support

Hi everyone,

First, thanks for this amazing library!

I customize one of my column to be like a "ignored", "accepted", or "declined" status along with its custom click event. But every time I have chosen the status, and select a row afterwards, it will automatically re render status to be the default one (ignored).

Is there anyone who knows how to prevent the data re-render when user selects a row?

Here is my test case: http://live.datatables.net/pokopiju/4/edit

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin
    Answer ✓

    Hi,

    This is an artefact of using FixedColumns I'm afraid. If you were to disable that it would work without a problem. The issue is that when you select a row, FixedColumns has to update in order to look like it has been selected, and that is basically causing it to rerender.

    The fix is to change the data that drives the checkboxes when a checkbox is checked. Then update the rendering function to have the correct one checked based on the data value and it will always be in sync.

    Allan

  • yusrilyusril Posts: 14Questions: 10Answers: 0

    @allan
    Hi Allan,

    Thanks for replaying. I have tried your suggestion by changing the data when clicking the checkbox and defining the checkbox condition via render option. But unfortunately, I still have no clue why it doesn't work.

    Would you like to have a peek on my demo? http://live.datatables.net/pokopiju/9/edit

  • yusrilyusril Posts: 14Questions: 10Answers: 0

    Hi @allan ,

    I just realized what you mean. So I need to also update the source of the data, which is the database in my case. So the table will request the new data along with the new status from database, don't I?

    But I am wondering, is there any other solution? How about if I disable the highlight of the selection only for the fixed column? will it still re-render the data?

  • allanallan Posts: 63,889Questions: 1Answers: 10,530 Site admin
    Answer ✓

    table.rows(tr).data()[0][5] = "Ignored";

    You need to also tell DataTables that the data has changed. If you do it like that, you need to use row().invalidate().

    Or use cell().data() to set the data and DataTables will know that you are updating the data.

    Allan

This discussion has been closed.