Option List Customization
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Option List Customization
I want to get option list of the current week and 7 weeks prior to this week to be auto-populated and the user to select, any help?
Like this?
Like this?
Re: Option List Customization
Alternative (1): JQuery plugin
Integrate a date range picker like this one:
https://www.jqueryscript.net/demo/Multi ... er-Plugin/
Scroll down to the example named "Batch mode ( week )" which automatically selects a whole week when selecting a date.
This is not out of the box. For integrating such a plugin you will need some programming knowlegdge in JQuery and Javascript.
There are more date range picker plugins available on the market, for example this one:
https://www.cssscript.com/date-range-picker-lightpick/
Integrate a date range picker like this one:
https://www.jqueryscript.net/demo/Multi ... er-Plugin/
Scroll down to the example named "Batch mode ( week )" which automatically selects a whole week when selecting a date.
This is not out of the box. For integrating such a plugin you will need some programming knowlegdge in JQuery and Javascript.
There are more date range picker plugins available on the market, for example this one:
https://www.cssscript.com/date-range-picker-lightpick/
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Option List Customization
Alternative (2): Additional "weeks" table
Create an additional table for weeks and populate it by PHP+SQL code. For example automatically insert all weeks till the end of the current yeay (or for the next 10 years or for the next three months ...).
Use that "weeks" table as lookup.
This solution could become be very flexible and can be integrated using built-in AppGini functions without any additional libraries or tools.
Example:
weeks
Insert can be done using PHP+SQL being called by a CRON job or after login or in an _init hook.
Create an additional table for weeks and populate it by PHP+SQL code. For example automatically insert all weeks till the end of the current yeay (or for the next 10 years or for the next three months ...).
Use that "weeks" table as lookup.
This solution could become be very flexible and can be integrated using built-in AppGini functions without any additional libraries or tools.
Example:
weeks
- id
- start {date, required, unique}
- end {date, required, unique}
- year {int, *}
- month {int, *}
- week {int, *}
Insert can be done using PHP+SQL being called by a CRON job or after login or in an _init hook.
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Option List Customization
The list will be a huge one, how can we have only few weeks around current date?jsetzer wrote: ↑2020-11-27 09:41Alternative (2): Additional "weeks" table
Create an additional table for weeks and populate it by PHP+SQL code. For example automatically insert all weeks till the end of the current yeay (or for the next 10 years or for the next three months ...).
Use that "weeks" table as lookup.
This solution could become be very flexible and can be integrated using built-in AppGini functions without any additional libraries or tools.
Example:
weeks* Year, month and week are optional by may (!) be very helpful later on for example for filtering using your lookup/Advanced SQL code.
- id
- start {date, required, unique}
- end {date, required, unique}
- year {int, *}
- month {int, *}
- week {int, *}
Insert can be done using PHP+SQL being called by a CRON job or after login or in an _init hook.
Re: Option List Customization
Just click [Advanced] button in lookup configuration and change the SQL code which controls fetching lookup data.... very helpful later on for example for filtering using your lookup/Advanced SQL code ...
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Option List Customization
Can't we use a code block like following to the DV.php and get the values at the form level?
Code: Select all
<?php
$PeriodWeekly = 8;
$monday = strtotime("last monday");
$monday = date('w', $monday)==date('w') ? $monday+7*86400 : $monday;
$sunday = strtotime(date("Y-m-d",$monday)." +6 days");
for($i=0; $i<=$PeriodWeekly;$i++){
$n = $i*7;
$start_date = date("Y-m-d",strtotime(date("Y-m-d",$monday)." -$n days"));
$end_date = date("Y-m-d",strtotime(date("Y-m-d",$sunday)." -$n days"));
<option value="<?php echo "$start_date to $end_date"; ?>"><?php echo "$start_date to $end_date"; ?></option>
}?>
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Option List Customization
Can't we use a code block like above in the DV.php and get the values at the form level?
Re: Option List Customization
Hi,
just a thought, you could use your code actually in the hooks/TABLENAME_init function to create the TABLENAME.FIELDNAME.csv file in the hooks folder, (see https://bigprof.com/appgini/help/advanc ... agic-files )
Like that you will always have the expected selection available.
One drawback, if you have an exiting record with a date selected that is not available in the newly created list (as it is already older than 7 weeks), the data will still be displayed in the tableview, but not in the detailview, as the reference to the possible selections will not be available any more.
just a thought, you could use your code actually in the hooks/TABLENAME_init function to create the TABLENAME.FIELDNAME.csv file in the hooks folder, (see https://bigprof.com/appgini/help/advanc ... agic-files )
Like that you will always have the expected selection available.
One drawback, if you have an exiting record with a date selected that is not available in the newly created list (as it is already older than 7 weeks), the data will still be displayed in the tableview, but not in the detailview, as the reference to the possible selections will not be available any more.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Option List Customization
hooks/TABLENAME_init function is an excelent idea....pböttcher wrote: ↑2020-11-28 20:31Hi,
just a thought, you could use your code actually in the hooks/TABLENAME_init function to create the TABLENAME.FIELDNAME.csv file in the hooks folder, (see https://bigprof.com/appgini/help/advanc ... agic-files )
Like that you will always have the expected selection available.
One drawback, if you have an exiting record with a date selected that is not available in the newly created list (as it is already older than 7 weeks), the data will still be displayed in the tableview, but not in the detailview, as the reference to the possible selections will not be available any more.
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Option List Customization
This is the code which should be put in hooks/table_name.php for init function
It will auto-populate the CSV file and that will be taken to option list
It will auto-populate the CSV file and that will be taken to option list
Code: Select all
function COVID_cases_init(&$options, $memberInfo, &$args) {
$PeriodWeekly = 8;
$file = '.\hooks\tablename.fieldname.csv';
file_put_contents('.\hooks\tablename.fieldname.csv', "");
$monday = strtotime("last monday");
$monday = date('w', $monday)==date('w') ? $monday+7*86400 : $monday;
$sunday = strtotime(date("Y-m-d",$monday)." +6 days");
for($i=0; $i<=$PeriodWeekly;$i++){
$n = $i*7;
$start_date = date("Y-m-d",strtotime(date("Y-m-d",$monday)." -$n days"));
$end_date = date("Y-m-d",strtotime(date("Y-m-d",$sunday)." -$n days"));
$current = $start_date . " to " . $end_date . ";;";
$current = file_get_contents($file);
$current .= $start_date . " to " . $end_date . ";;";
file_put_contents($file, $current);
}
return TRUE;
}
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Option List Customization
To make the dates descending change the common.js.php below section
"return b.text > a.text;" instead of "return a.text > b.text;"
"return b.text > a.text;" instead of "return a.text > b.text;"
Code: Select all
/* function to sort select2 search results by relevence */
AppGini.sortSelect2ByRelevence = function(res, cont, qry) {
return res.sort(function(a, b) {
if(qry.term) {
var aStart = a.text.match(new RegExp("^" + qry.term, "i")) !== null;
var bStart = b.text.match(new RegExp("^" + qry.term, "i")) !== null;
if(aStart && !bStart) return false;
if(!aStart && bStart) return true;
}
return b.text > a.text;
});
}
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Option List Customization
Does this happen every time someone lands on the form?
I assume the list is always Monday to Sunday, so this list would change weekly as opposed to daily.
Thanks.
~Paul
I assume the list is always Monday to Sunday, so this list would change weekly as opposed to daily.
Thanks.
~Paul
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Option List Customization
Yes the list will be auto generated each time you load the detail view. Date ranges will be generated based on the current date