Buy Now
Sign in

Export selected rows to csv

Elitakey , February 25 at 20:08
Answered
E
Elitakey
Hello to all.
I have working CCv6 table with select submission chekbox that i created from demo table "Articles list with advanced features" and csv export button that export all the records from the data table with data provider {var:read_submissions.[n].Submission} where read_submissions is db read function and Submission is model. Litererarly. all data nevertheless i defined Titles in the csv export function.
Question is - how to create csv export so it exported only selected records with only defined columns?
thank yo in advance -
Elita
E
Elitakey
Max, you have got this implemented in CF6 DB table view. Please, share the knowledge with everybody
1.png
Attachments
1.png
1.png
(45.39 KiB)
250 Downloads/Views
C
currucutaco
Please answer this question I have the same doubt
admin
Hi,
  1. in the Toolbar button view settings enable the "Submit button" option.
  2. In the selector view, set the "Value" to {var:table_view_name.row.Model.primary_key_name}
Now when you select some checkboxes and click the toolbar button you will get a list of primary keys under the "gcb" data var, use this in your "Read data" to select the records, the where conditions should be:
Model.primar_key/in:{data:gcb}
Then after the records are loaded you can use them in the CSV action or anywhere else.
Best regards
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
E
Elitakey
What is Data provider in CSV export function in this case?
Found this in other posts - is this applicable in this case?
{var:read_fn.[n].Model_name}
admin
Hi Elita,
Yes, since you read the records using the read data that should work.
Best regards
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
E
Elitakey
Max, something is not right here.
Should I use separate Read Data function for this purpose?
If I put the code you provided Model.primary_key/in:{data:gcb} in Read action for either Read Data for the Table or Read Data for the Row
I got an error:
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''' at line 1
And what is the Select Type then? First maching record or All matcing records?
admin
Hi Elita,
The conditions need to be for the "Read data" of the table, and you need to set the select type to "All matching" since you are using the results for the table.
Did you replace "primary_key" and "Model" in the syntax ?
Best regards
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
E
Elitakey
Yupp. I Have Read Data for the Table view with "All matching" with Model named Submission. When I put code you provided e.g. Submission.aid/in:{data:gcb} I got an error mentioned above. only by opening the Table view. To be more precise - everything is working - Table opens, all other functions and views work untill I put that code in.
P.S. If it matters - My Joomla version is 3.8.3 and other settings: PHP 7.1.15; MySQLi 5.7.21-0ubuntu0.16.04.1
admin
Hi Elita,
Your selector field name is set to gcb[] ?
Best regards
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
E
Elitakey
Hello, Max, yes. it is set to gcb[]. And value is set to {var:submissions_list.row.Submission.aid} where subbmisions_list is Table, Submission - Model and aid- submission id.
admin
Then debuging is needed, in the csv event (The event to which the export button is pointing), use {debug:}, what do you get when you try to export ?
Best regards
Max
If your main question got answered then please mark the answer using the button!​
​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
E
Elitakey
Figured everything out. Took some time. The only problem is - cannot get UTF-8 latin extended characters.
Any idea, Max?
Thank you in advance - Elita
E
Elitakey
***** How to create checked rows CSV Export for CCv6 Table*****
1. Create new Read Data function, e.g. read_submissions_csv with Model name e.g. Submission and Where conditions aid/in:{data:gcb} where aid - DB id field; add Fields to retrieve if you want only certain DB data to be exported in CSV. Data settings - All matching records. ​
​2. Create CSV function, e.g. export_csv with Data provider {var:read_submissions_csv.[n
  • .Submission}, add titles for your data export in field Titles, change Delimiter to ; if you want to open that file in Excel. If necessary, define file name by adding, for example, Date created:​
    ​{date:YmdHis}_CSV.csv ​
    ​3. Create Event e.g. csv_export with both Function calls:​
    ​{fn:read_submissions_csv}​
    ​{fn:export_csv}​
    ​4. Create Toolbar Button e.g. export_csv_button with the Event - csv_export, Subbmit button? - Checked, List view name - Table name where rows are going to be selected. e.g. submissions_list and Selections requred? - Checked.​
    ​5. Add this button to the default Event index or other event where Table view is called - {view:export_csv_button};
    ​6. Create Selector e.g. select_submission with Checkbox field name - gcb
  • and Value - {var:submissions_list.row.Submission.aid};​
    ​7. Create Selector select_all; ​
    ​8. Add selectors to Table view - select:{view:select_all} in Columns list; select:{view:select_submission} in Columns views. ​
    NB! - Include form? Should be switched on;
    E
    Elitakey
    Things to consider though:
    1. How to get Latin extended characters properly shown in Excel; (like ā,ē,ļ,);
    2. How to define data so Excel would not convert everything that look like date to date format; E.g. - if data is stored like 12/23/18.
    Hoping to get the solution -
    Elita
    admin
    Hi Elita,
    1. The file data has the same encoding of the database table, so when you open the file in excel you need to choose utf-8 as the view encoding.
    2. I think this also should be a configurable Excel setting.
    Best regards
    Max
    If your main question got answered then please mark the answer using the button!​
    ​Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!