Welcome to the nuBuilder Forums!

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

Filter rows

Questions related to using nuBuilder Forte.
Locked
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

Filter rows

Unread post 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
You do not have the required permissions to view the files attached to this post.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Filter rows

Unread post 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
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Filter rows

Unread post 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 =  '&nbsp;&nbsp;&nbsp;&nbsp;<label for="check' + i + '">'+ nuTranslate(v) +'</label><input type="checkbox" value="check" id="check' + i + '" onclick = "'+f+'"/>&nbsp;';
  $('#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);

}
You do not have the required permissions to view the files attached to this post.
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

Re: Filter rows

Unread post by marc »

I was able to adapt your code to my needs and it works perfectly! Thanks toms!
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Filter rows

Unread post by admin »

.
Locked