Page 1 of 1
Filter rows
Posted: Mon May 14, 2018 3:37 pm
by marc
Hi all,
I have a requirement where I would like to have a checkbox to filter rows.
Checkbox status:
Checked -> show all rows with a date (column End Date)
Unchecked -> show all rows (with End date or not)
How do I refresh the Browse Form and apply the filter?
browse_filter.png
Re: Filter rows
Posted: Wed May 16, 2018 2:53 am
by admin
marc,
What you are wanting to do is not the way nuBuilder does things.
I suggest you create another column that contains something like 'HasDate' or 'NoDate' - based on the date column.
That way you can filter using the normal search feature (without any extra programming).
Steven
Re: Filter rows
Posted: Tue Jul 03, 2018 11:28 am
by toms
Hi,
If you are still looking for a solution...
I have a browse form which initially only displays the data as of today. By clicking the checkbox "Show All" all data will be displayed. You may adapt it to your needs.
Short video:
https://vimeo.com/278120734
browse_filter_dates.png
Browse SQL:
Code: Select all
SELECT
*
FROM
my_table
WHERE
(
(
LOCATE('#', '#custDateFilter#') = 1
OR '#custDateFilter#' = 'false'
)
AND my_date >= CURDATE()
)
OR (
LOCATE('#', '#custDateFilter#') <> 1
and '#custDateFilter#' <> 'false'
)
ORDER BY
my_date
Add this Javascript to your Form:
Code: Select all
function nuAddActionCheckbox(i, v, f){
var chk = ' <label for="check' + i + '">'+ nuTranslate(v) +'</label><input type="checkbox" value="check" id="check' + i + '" onclick = "'+f+'"/> ';
$('#nuActionHolder').append(chk);
}
if (nuFormType() == 'browse') {
nuAddActionCheckbox("custDateFilter", "Show All", "custSetDateFilter(this)");
$('#nuBrowseFooter').after($('#checkcustDateFilter'));
$('#nuBrowseFooter').after($('label[for=checkcustDateFilter]'));
$('label[for=checkcustDateFilter]').css('position', 'relative');
$('#checkcustDateFilter').attr('checked', nuGetProperty('custDateFilter'));
}
function custSetDateFilter(chk) {
nuSetProperty('custDateFilter', $(chk).is(':checked'));
nuSearchAction(1);
}
Re: Filter rows
Posted: Fri Jul 06, 2018 8:22 am
by marc
I was able to adapt your code to my needs and it works perfectly! Thanks toms!
Re: Filter rows
Posted: Fri Jul 06, 2018 8:04 pm
by admin
.