Page 1 of 1

Select and order fields for a subform by the user and output

PostPosted: Sat Aug 01, 2020 4:09 pm
by ernesttan1976
Hi to all, I really appreciate the developers of this software.

I created a subform called employees.
In this subform I am able to edit the fields which is really cool.

For browse forms, there is a print and download to csv feature which I very much appreciate. I want to be able to select and order the fields shown in the subform so that it is user customizable, and then the user can output it as a csv.

May I know how to go about this?

Re: Select and order fields for a subform by the user and ou

PostPosted: Sat Aug 01, 2020 7:16 pm
by kev1n
I'm afraid it'is not so easy to change the order of the columns/fields.
To output just certain fields in the CSV, you would have to write your own custom JS or PHP function. Maybe someone else will come up with other ideas.

Re: Select and order fields for a subform by the user and ou

PostPosted: Sun Aug 02, 2020 2:32 am
by gerese
For example, you can create 4 different forms using the same table, in which the order or number of columns is closest to the user's needs.

Re: Select and order fields for a subform by the user and ou

PostPosted: Sun Aug 02, 2020 4:25 am
by Janusz
Maybe you can try to generate CSV from the MariaDB using PHP procedure and store it on the server.
Next open saved file from nuBuilder.
Something like that (PHP procedure):

Code: Select all
unlink('/var/www/html/TestDB/temp/customers.csv');

$q ="
SELECT kon_nazwisko, kon_email, kon_tel INTO OUTFILE '/var/www/html/TestDB/temp/customers.csv'
  FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\"'
  LINES TERMINATED BY '\n'
  FROM Kontakty;
";

nuRunQuery($q);

$x="window.open ('temp/customers.csv',\"myWindow\");";

nuJavascriptCallback($x);

You can create $q variable with JS and send it to the PHP (or better just a part of it).
Procedure you can run with:
nuRunPHPHidden('CSV_test', '1');

it's just an idea not well tested - but the attached code was working with quick test with my data.

Re: Select and order fields for a subform by the user and ou

PostPosted: Mon Aug 03, 2020 12:48 pm
by ernesttan1976
Thanks Kevin cheers!

Janusz, thank you very much for your help! :D :) I will try it out and post my result. :D :)

Re: Select and order fields for a subform by the user and ou

PostPosted: Tue Aug 04, 2020 4:30 am
by Janusz
If you want to "separate" the file user by user and add column names you can run following procedure:
Code: Select all
$file="#user_id#customers.csv";
$list= " kon_nazwisko, kon_email , kon_tel ";
$table= " Kontakty ";
$column_names=" 'Col_1', 'Col_2', 'Col_3' ";

unlink("/var/www/html/TestDB/temp/$file");

$q ="
SELECT *
INTO OUTFILE '/var/www/html/TestDB/temp/$file'
FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
FROM
(SELECT $column_names
UNION
SELECT $list FROM $table) AS temp
";

nuRunQuery($q);
$x="window.open ('temp/$file',\"myWindow\");";

nuJavascriptCallback($x);

Re: Select and order fields for a subform by the user and ou

PostPosted: Tue Aug 04, 2020 5:15 pm
by kev1n
I'm developing a script that will allow you to hide and rearrange columns of a subform. I'll need some more time to finalize it but here's a sneak peek:

Re: Select and order fields for a subform by the user and ou

PostPosted: Tue Aug 04, 2020 6:00 pm
by kev1n
PS: Kindly refrain from asking multiple questions in the same thread. If people start answering multiple questions in the one thread, it becomes very confusing very quickly and it makes it harder for everyone.