Table Local Storage Data reload
Table Local Storage Data reload
Shuttering
Posts: 1Questions: 1Answers: 0
I want to update my data in my table when a value changed in my firebase database. I'm a beginner and have no idea how to do that, and after a long unsuccessful search on the forum i need your help
Here is my code:
var table = $('#datatables').DataTable({
dom: 'lBfrtip',
responsive: true,
data: $.map(localSave, function (value, key) {
return value;
}),
columns: [
{ data: "c1", render: editIcon },
{ data: "c2", render: editIcon },
{ data: "e1", render: editIcon },
],
select: true,
buttons: [
{ extend: 'create', editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor },
{
extend: 'excel', text: 'Excel', exportOptions: {
modifier: {
page: 'current'
}
}
},
{
extend: 'pdf', text: 'Pdf', exportOptions: {
//modifier: { page: 'current'}
}
},
{
extend: 'print', text: 'Drucken',
autoPrint: true
},
{
extend: 'copy',
text: 'Kopieren',
}
],
});
var userId = this.userDetails.uid;
this.db.database.ref("db link...").once('child_changed').then(function (snapshot) {
if (snapshot.exists) {
localSave = snapshot.val();
localStorage.setItem(savePlace, JSON.stringify(localSave));
//Here I would like to update the table
}
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm not clear on exactly what your code is doing or how / where you get the firebase data. Not familiar with firebase either I see you are doing this for the initial data load:
Does
localSave
contain all or one record at this point?If all you could use
clear()
thenrows.add()
followed bydraw()
. I suspect you will want to add the rows with themap
command.If one row do you want to simply add it? You can use
row.add()
Or do you need to find and update a particular row? To help with this we would need to have an example of your data. Do you have a unique data column? We would need a way to find the row then use
data()
to update.Kevin