Forums

Export selected rows to csv

Elita- 25 Feb, 2018
1 Likes
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
Elita- 27 Feb, 2018
Max, you have got this implemented in CF6 DB table view. Please, share the knowledge with everybody๐Ÿ˜€
โ€‹
currucutaco 08 Mar, 2018
Please answer this question ๐Ÿ˜‰ I have the same doubt
Max_admin 08 Mar, 2018
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, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 09 Mar, 2018
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}
Max_admin 09 Mar, 2018
Hi Elita,
โ€‹
Yes, since you read the records using the read data that should work.
โ€‹
Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 09 Mar, 2018
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?
Max_admin 12 Mar, 2018
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, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 12 Mar, 2018
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
Max_admin 13 Mar, 2018
Hi Elita,
โ€‹
Your selector field name is set to gcb[] ?
โ€‹
Best regards
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 15 Mar, 2018
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.
Max_admin 15 Mar, 2018
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, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 17 Mar, 2018
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
Elita- 17 Mar, 2018
Answer
***** 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} (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. [br]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;
โ€‹
Important! Dont mess with the Model name in all the functions. They should be the same.
Elita- 17 Mar, 2018
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
Max_admin 18 Mar, 2018
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, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.