How to refresh one single row after changing data in the backing bean

How to refresh one single row after changing data in the backing bean

rgdomsrgdoms Posts: 1Questions: 1Answers: 0

Good morning,
I'm kinda newbie in this forum.
I have a backing bean that supplies the datatable.
In the frontend I have a button that changes some data of a row in the server side.
Just for proof of concept I'm trying to update (via another button click) **only the row involved **in this operation.

My first approach was to make a ajax update of all table (with jsf update), and it goes well, but all the table is redrawn, pagination is lost, and the user is relocate at page 1.

After I tried:
$('.mydatatableclass').DataTable().cell(0,0).invalidate().draw()
and
$('.mydatatableclass').DataTable().cell(0,0).draw()

but nothing happens.

After I tried:
$('.mydatatableclass').DataTable().cell(0,0).data('NEW content').draw()
This actually changes the content of the cell to 'NEW content', but I'm changing in client side, not mirroring the server-side changed data.
Alongside with this, user is relocate on page 1, if he is in other page greater than 1.

Can you help me? Is there a way to refresh/redraw the cells, making it to fetch data from server, or this doesn't this make any sense, in this context?
If there is no way to do this, is there at least, a way to keep the user in the same page, using this last approach?

Thanks in advance.
Rui

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    invalidate() should be used if the internal cache is inconsistent with the table's data. In your case, it isn't inconsistent, the ajax reload just updated it, and the cache would've been updated too - so I'd expect it to do nothing here.

    This actually changes the content of the cell to 'NEW content', but I'm changing in client side, not mirroring the server-side changed data.

    Yep, if you want to update the server, you'll need to send that back to the server too. Editor would do this for you automatically (with edit(). Without it, that's an operation you'll need to code.

    Can you help me? Is there a way to refresh/redraw the cells, making it to fetch data from server, or this doesn't this make any sense, in this context?

    You should just be able to call ajax.reload() - the second param determines whether the paging is reset. If you want it held, try ajax.reload(null, true).

    Colin

This discussion has been closed.