Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

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

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
ernesttan1976
Posts: 51
Joined: Sat May 16, 2020 10:08 am

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

Unread post 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?
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

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

Unread post 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.
gerese
Posts: 132
Joined: Sun Dec 16, 2018 6:13 pm
Location: România
Has thanked: 30 times
Been thanked: 4 times

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

Unread post 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.
nuBuilderForte .... BIG Like !!!
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

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

Unread post 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.
If you like nuBuilder, please leave a review on SourceForge
ernesttan1976
Posts: 51
Joined: Sat May 16, 2020 10:08 am

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

Unread post by ernesttan1976 »

Thanks Kevin cheers!

Janusz, thank you very much for your help! :D :) I will try it out and post my result. :D :)
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

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

Unread post 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);
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

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

Unread post 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:
You do not have the required permissions to view the files attached to this post.
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

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

Unread post 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.
Post Reply