I want to use two functionalities of DataTables how do I do that?
I want to use two functionalities of DataTables how do I do that?
1).I have a json data which originally looks like this:
var button_data = {"state":"on", "operation":"
" }
I convert this data to this format:
var button_data = {"state":"<input type='submit' value='on'}
Now i use this json data to print it in the DataTable which displays it as buttons in the DataTable.
2).The second functionality that I want to implement is to use the original button_data and through the File Export of DataTable (https://datatables.net/extensions/buttons/examples/initialisation/export.html) get all the details in pdf,excel,etc format.
My question is how do i use both these functionalities together as you can initialize Datatable only once. Plus the other thing is that in the 2nd functionality i want to export only the state key and its value and not operation in the original button_data variable.
Answers
I'm afraid I don't really understand what
_button_data
is used for. Is that a row in the DataTable? Can you link to a page showing the issue as required in the forum rules.Thanks,
Allan
Hey Allan thanks for the quick reply so here is the examplehttp://live.datatables.net/nifaquvo/1/edit
In the example you can see that i have two javascript variables namely
button_data
anddata
.data
is used to populate the DataTable which I have already done. Now I want to usebutton_data
for the The File Export Functionality(https://datatables.net/extensions/buttons/examples/initialisation/export.html) in DataTable but I only want state to be exported and not name in that. How do i do this.Thanks for the link. There is no direct option to do what you are looking for in Buttons at the moment. Having said that, there are two options to be able to control the output data:
The first option is probably the best option for you here and you can use the API to get each cell in the table (
cell().node()
) read the state and then return the required value.Allan
Hey Allan thanks for the help but there seems to be a small problem i am getting undefined values for the data when I am exporting it. Here is my code http://live.datatables.net/nifaquvo/4/edit please let me know where i am going wrong. I want the data in the
button_data
to be exported.The function that is given is called for every cell - see the documentation for
buttons.exportData()
. So it needs to return the data for each cell in turn. So if you want to usebutton_data
as an external data source you would need to access its elements directly and return them.Sorry i did not catch that do I have to return
button_data
in thebuttonCommon
function or do I use thebutton_exportData()
API in the buttonCommon function, store it in a variable and then return it. I read through the API but i do not know where to implement it. Please tell me what snippet of code I need to add and where i need to add it.Thanks!!!I'd be happy to write the code for you under the support options.
As I say, you your function will be executed once for every cell - so if you have 5 columns and 50 rows, it would be executed 250 times. It would return the data for each cell, as required, each time.
Allan