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?

codeiuscodeius Posts: 7Questions: 3Answers: 0

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

  • allanallan Posts: 62,012Questions: 1Answers: 10,166 Site admin

    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

  • codeiuscodeius Posts: 7Questions: 3Answers: 0
    edited March 2016

    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 and data. data is used to populate the DataTable which I have already done. Now I want to use
    button_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.

  • allanallan Posts: 62,012Questions: 1Answers: 10,166 Site admin

    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

  • codeiuscodeius Posts: 7Questions: 3Answers: 0

    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.

  • allanallan Posts: 62,012Questions: 1Answers: 10,166 Site admin

    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 use button_data as an external data source you would need to access its elements directly and return them.

  • codeiuscodeius Posts: 7Questions: 3Answers: 0

    Sorry i did not catch that do I have to return button_data in the buttonCommon function or do I use the button_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!!!

  • allanallan Posts: 62,012Questions: 1Answers: 10,166 Site admin

    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

This discussion has been closed.