Custom query on button
Custom query on button
m75sa
Posts: 132Questions: 30Answers: 0
in DataTables
Hi, I would like to add a custom button to export .txt file that execute a customized mysql query.
What i can see is that i can customized columns shown on the table but in my case i don't have columns shown so the quey must show only result into the exported .txt file.
Any ideas?
Thanks for the support
This question has an accepted answers - jump to answer
Answers
I don't understand the part about not having columns shown in the table. If you are using the Buttons extension you can create a custom button. See this example. The Action function can be any code you create to execute the MySql query and save to a text file.
Kevin
@kthorngren i try to explain.
I have my table that comes from mysql query such as:
name + surname + age
and buttons that export pdf, csv and print.
Now if i click on the button the export shows only the result of name + surname + age so what i see on screen.
What i want is an additional button (called i.e. txt) that exports in txt format the following columns:
name + surname + age + phonenr
so phone nr is in the same table of name + surname + age...
so i think that i need to query the database with the phonenr too...
how to do?
any help?
It might be easier to return all the data to the table - but hide those columns are view - using
columns.visible
. You can then export them by doing something like this:See example here: http://live.datatables.net/qitayeva/1/edit
Colin
thanks colin, this could work but if i have to export a .txt file with items separated by commas?
The CSVHtml5 options docs show all the options available. See if the
fieldSeparator
will change the format to remove the commas.Kevin
Yep, the export code I posted could be used for both PDF, CSV, and any other export type.
Colin
thanks colin. Is there a way to skip the first row on the csv exported file? I don't want the columns header title...
This thread should help, it's asking the same thing.
Cheers,
Colin
thanks a lot.
Back to my previous question, i was able to hide columns during the export (this is good) but i didn't found a solution how to hide columns when table is shown so not when i export...
any help on this? Sorry to press you but i'm in panic...
I'm not clear what that means, I'm afraid. Do you mean something like the "colvis" button - see example here.
If not, please provide a test case with steps on how to reproduce the issue. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin