Export format for multi-select Dropdown Element

bggann

Active Member
I have a dropdown element for which multiple select is allowed.
If I do CSV export of that list, the data in that element is exported in a form that makes parsing it difficult.

For instance.
If my dropdown has the choices.
- Choice One
- Choice Two
- Choice Three

and I select "Choice One" and "Choice Three"
then the CSV export combines these into one feild
"Choice One Choice Three"
There is no delimiter in there so it is very hard to parse the field.
If I choose to Include Raw Data then the field is exported as
["Choice One","Choice Three"]
so I could potentially parse that - but then I get all the raw data, which I don't want.

Any way to get this to export with a delimiter of some sort?

- bob
 
Okay - I got no responses here which makes me think that either nobody has an idea, or it is not possible.

So - what I did was edit the csvexport.php file in models to special case the field I'm worried about.

The problem with this is, of course, if Fabrik is upgraded, I have to either "redo" this code, or make sure that one file is not updated.

- Is there a better way to do this - kind of like custom templates or something - so I don't have to worry about replacing the code every upgrade?
- Is there a way to tell if the field is of the multi-select dropdown then process it automatically rather than hard code the field name. I could not find that in the structure in csvexport.

I'd rather come up with a generic solution that recognizes a multi-select dropdown and parses it correctly.
I'd be willing to code it up as an enhancement to Fabrik if somebody can guide me....
The problem is, this data is stored in the database as a string/text and then parsed by Fabrik.
The other problem is that the number of elements, thus the number of columns required depends on the data.

Bob
FYI - I added the code that follows. Definitely a cluge.

// special processing for Bruce for additional msos - BGann
if($key == 'daily_log_7_repeat___names_of_additional_msos')
{
$rawkey = $key . '_raw';
$rawvalue = str_replace(',','|',$a[$rawkey]);
$rawvalue = str_replace('"','',$rawvalue);
$rawvalue = str_replace('[','',$rawvalue);
$rawvalue = str_replace(']','',$rawvalue);
$a[$key] = $rawvalue;
}
// End of special processing. BGann

What this does is use the _raw value which is formated as ["value one","value two","value three"]
and make it
value one|value two|value three
in the CSV exported data.

Kind of a nasty work around, but it works. We can use "text to data" in Excel to split those values.

-----------------------
 
Ooops, sorry, don't know how I missed your post and bump in December, my apologies. I think that was the week I was out of town, helping family move house 3 states away.

I think the only way to work this is to add one or maybe two options for how to deal with repeated data.

Most obvious would be "separator character" for non-raw data.

Then perhaps a "Use JSON for raw data". If set to yes, use the standard JSON format (the ["foo","bar"] format), if No then format raw data the same as non-raw, using the sepchar.

Would those two options work for you?

-- hugh
 
Hey Hugh,

No problem. This is definitely a bit of a corner case (I seem to find those).

The solutions you mention would be fine. The 'separator' character is basically what I did in my hack and it is a good solution if you can figure out how to identify those values other than the hardcoded name I used. Ideally, you'd probably want to specify the separator, but it would probably work to just use | like I did.

Would this change be in csvexport like I made mine. I'd like to understand how to make it generic. I couldn't figure out by looking at structures in jdump, but I didn't look hard....

If you can point me at the right place to do it, I'd take a stab at making the changes and save you the work.

-bob
 
Code:
but it would probably work to just use | like I did

Might work for you, but I can 100% guarantee whatever character I use, as soon as I do it, someone will want a different one, or will want it in JSON format.

It'd have to be a param in the list XML, in the CSV param group, fetched with $params->get() (should be plenty of other examples of how to use params in the code. And language strings would have to be added for the new setting.

-- hugh
 
Okay-

I managed to add a "Dropdown data delimiter" label, description and field to the CSV export form for lists. Modified the 'ini' language file and the .xml file to add the field to the form.
I did not add the JSON raw one - but I know how - now.

Now - I don't know where to do the processing.....
I'll keep investigating, but it'll be tomorrow.

For reference, here is what I added.
list.xml
<field name="csv_repeat_delimiter"
type="text"
class="input-mini"
size="20"
default=""
label="COM_FABRIK_FIELD_CSV_DROPDOWN_DELIMITER_LABEL"
description="COM_FABRIK_FIELD_CSV_DROPDOWN_DELIMITER_DESC"
/>

en-gb.com_fabrik.inin
COM_FABRIK_FIELD_CSV_DROPDOWN_DELIMITER_LABEL="Dropdown Data Delimiter"
COM_FABRIK_FIELD_CSV_DROPDOWN_DELIMITER_DESC="Enter the delimiter to be used to seperate elements in multi-select dropdown fields when exporting to CSV"
 
No, no, no. I did it on my development site. I thought I'd get a bit there before I mess with a fork that may turn into a knife and stab me....
 
:)

You can always run your local site on a fork.

Checkout the project, create a branch, then just copy the whole folder over to your J! root.

-- hugh
 
Github has a steep learning curve, but once you figure it out, it's worth it. Especially for test sites. One big win is that if your site is running on a github clone, you can update with a couple of simple commands (git fetch, git merge upstream, git pull), and if you have issues, you can just "git revert ...". And if you have changes you want to submit, "git push" then use the git hub website to create a PR on our repo.

-- hugh
 
Yeah - I used Github many moons ago and I'm sure I've forgotten what I knew, and what I haven't forgotten probably changed... I'll dig into it.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top