Storing table-scope property in dataset
Storing table-scope property in dataset
Howdy, I have a following dataset structure as example, which is being returned from my custom ajax:
{
globalFieldA: gfA,
globalFieldB: gfB,
rowData: [{
row1Name: name1,
row1Prop: prop1
},
{
row2Name: name2,
row2Prop: prop2
}]
}
Now, the question is:
how can I feed my datatable with given global fields globalFieldA, globalFieldB to make it accesible to footer callback, with table rows feeding off the rowData? I would like to avoid to store the dataset in intermediate structure to only have a single point of truth in datatables themselves trough all my processes. Thanks in advance!
This question has an accepted answers - jump to answer
Answers
Assuming you have it being loaded by custom Ajax, do you have a reference to the object? Perhaps you can show your initialisation code?
Allan
Sure thing, here is my initialisation, i have several instances of it on the page:
here I am using $table.data, for example, but I find it kinda unsettling to have the row data in datatables data layer and several related to the whole table ones on jquery.data().
You have the
dataset
property, so you should be able to access that in the footerCallback - e.g.dataset.globalFieldA
. Or have I missed the point?Allan
True, I do have access, of course, but the given
dataset
is only used during initialisation, afterwards ajax events do directly change the data in tables themselves. SincefooterCallback
fires on draw event, it would mean that footer would be just redrawn with initial data.So, my option would be to either write on ajax event into datatables AND mutate inital
dataset
, so footer reads from there (what could create a confusion), to put the needed global field onto every single row or to use additionaljquery.data
field, as I do right now.Unfortunately, there is no way to direclty set the data for headers/footers explicitly, as far I understand, right?
Cheers
I don't quite get what you mean I'm afraid - specifically about the ajax events changing the data. Do you mean they use things like
row().data()
to modify the data in the table, and thus the information in thedataset
would no longer be in-sync?If that is the case, do those ajax events get the updated data for
globalFieldA
etc as well? If so, can you write them into a global variable that can be accessed by the footer callback?Currently no - sorry. That is something that will be added in the next major version.
Allan