Redraw a row after ajax updated (using bootstrap modal)
Redraw a row after ajax updated (using bootstrap modal)
beegeezzz
Posts: 12Questions: 3Answers: 0
Hello everybody,
Hope you ara doing well...
I update a row with AJAX, all is OK, but when I close the bootstrap modal (contening the update form), I would like to redraw the row without relaod the page.
The problem is that I'm using a bootstrap modal and my dataTable is outside this modal.
I tried this code
success:function(result)
{
$("#result").show(); //DD: il faut le laisser autrement, il n'appraît plus quand on met à jour un second prestataire...
$("#result").html(result);
$("#result").fadeOut(3000);
table
.row( $(this).parents('tr') )
.draw();
}
but the row contains the old information.
table contains this
var table = $('#example').DataTable();
Thanks in adavance for your help.
David
This discussion has been closed.
Answers
I think you might need to use
row().invalidate()
, for example:Kevin
Hello,
Thank you for your reply.
Unfortunately, it does not work for me.
I still have to refresh the page to see the new value.
Please, see this video, I recorded my screen to show you :
partnering4biotech.com/datatable.mov
Thanks again for your help
What does
$("#result")
refer to and what is the content ofresult
?I assume you are trying to update the cell or row with this?
$("#result").html(result);
Making assumptions that your success response
result
contains the updated row and you are wanting to update the row html with$("#result").html(result);
. If this is the case then it suggests to me that "#result" is the incorrect row selector.Once you get the row html updated then you use
row().invalidate()
to have DT update its cached data from updated html.I may be off base with my assumptions, just taking my best guess.
Kevin
Hello
Thanks for your quick reply.
contains only a message to say something like "Update OK" or "Insert OK".
I think the main problem is that my bootstrap modal takes the focus and I'm not able to work on my dataTable.
I think also (I'm not sure) I have to send new content from PHP to feed the table ?
This is a part of my php code
The controller
The model
And my js code
Like you can see, I don't return any new information to put in the dataTable.
Do you think that I have to return information or can I update my dataTable without returning any information from PHP ?
Thanks for all.
David
There is a z-index property you might be able to apply to the popup message to force it in front of the bootstrap modal.
Probably what I would look at doing is having my server script update the DB then retrieve the record and return it in the ajax response. Then use the
success
function to update the Datatable usingcell.data()
orrow.data()
depending on what you return.Kevin
Hello Kevin,
Thank you very much for your reply and sorry for the delay of mine.
I tried, I tried and I tired, but no result so far...
My idea is to build in php the table and return it to js like this
I work on this id
I use a SELECT query
I build the table
and in javascript, I use html to rebuild the tbody :
I loose some effects (like color...) and I think that's not the best way.
What do you think ?
Have you something better for me please ?
Thank you again
David
I would suggest you just have the server return a simple JSON structure with the data only - i.e. no class information. Then use data renderers to add classes and HTML to the buttons as required.
That way you won't need to use
$().html()
directly. You can do that, but it will overwrite whatever DataTables has put in the table.Allan