Can local data be updated with Edit Tool?
Can local data be updated with Edit Tool?
Hi. It was fairly easy to get local data{} into a table. I haven't been able to get the data updated using the update tools. Is there a good example?
Using https://editor.datatables.net/examples/advanced/localstorage.html, I can update the table, but not the but not the underlying data. On refresh, the "deleted" record simply comes back.
Needless to say, I don't know what I am doing!
Thanks & regards,
nmo.
Data:
>
{
"heatmapdata": [
{
"id": "1747",
"floc": "AU01.S18EPL001",
"drawing": "EARTH,ELECTRODE PIT,LGTG,SUB 18 (B8318)",
"description": "L4018DE300.0002",
"r": "0.003333333",
"x": "1",
"y": 2",
"risk": "a",
"size": "a"
},
{
"id": "1606",
"floc": "AU01.5A1430EPL002",
"drawing": "EARTH,ELECTRODE PIT,LGTG,(5A1430)",
"description": "L4003DE312.0005",
"r": "2",
"x": "12",
"y": 4",
"risk": "a",
"size": "100"
}
]
}
Editor is:
editor = new $.fn.dataTable.Editor({
Data: whatever.heatmapdata,
idSrc: "id",
table: "#datatab",
fields: [
{ label: "floc", name: "Floc" },
{ label: "risk", name: "Risk" },
{ label: "description", name: "Description" },
{ label: "r", name: "Value" },
{ label: "x", name: "Lat" },
{ label: "y", name: "Long" }
],
ajax: function (method, url, d, successCallback, errorCallback) {
var output = { data: [] };
if (d.action === 'remove') {
// Remove items from the object
alert("hi0");
$.each(d.data, function (id) { delete whatever.heatmapdata[id]; });
}
simpleStorage.set("data", whatever);
successCallback(output);
}
});
and the table looks like this:
$('#datatab').dataTable({
Data: whatever.heatmapdata,
dom: 'Bfrtip',
columns: [
{ "Data": "floc" },
{ "Data": "risk" },
{ "Data": "description" },
{ "Data": "r" },
{ "Data": "y" },
{ "Data": "x" }
// { data: null,
// className: "center",
// defaultContent: '<a href="">locate</a>'
// }
],
select: true,
buttons: [
{ extend: "edit", editor: editor },
{ extend: "create", editor: editor },
{ extend: "remove", editor: editor }
]
});
This question has an accepted answers - jump to answer
Answers
Does that happen in the localStorage example you linked to for you? I've just tried it and it works as expected for me (Chrome / Mac).
Allan
Ok, thanks, it does work but the example wasn't quite what I needed.
My problem is that I can't send any data to the server due to my company IT policy, so I am working with data loaded from excel on the client side only.
I managed to use the client side validation example to do all the manipulation I needed at the pre-submit stage, redraw the affected rows and then return false from the pre-submit.
There may be a better way, but this works for now!
Thank you for the excellent library.