1. Data filtering

    Article: AN0001910Updated: 23.09.2018

    Filter on a button

    It is possible to use a button in the list of records which will set the filter to the requested values.

    We will create a button of the type Script:

    //clears possible existing filter
    OGFilter.Clear();

    // sets the filter to the requested values
    OGFilter.Add( true, 'status', '!=', 'resolved');
    OGFilter.Add( true, 'status', '!=', 'deferred');
    OGFilter.Add( true, 'status', '!=', 'canceled');
    OGFilter.Add( true, 'status', '!=', 'todeploy');
    OGFilter.Add( true, 'assignto', '=', OG.Person.GetLoginPerson());

    //applies the filter
    OGFilter.Run();

    //packs the block with filter
    OGFilter.Minimize();

    The resulting filter block looks after clicking like this:

    You use following values/objects in the last parameter of the method OGFilter.Add:

    Filter on a button 2

    The following example creates a filter with brackets.

    // Column Name contains word 'calendar' and column Status equals New, For testing or To provide more information

    //clears possible existing filter
    OGFilter.Clear();

    // sets the filter to the requested values
    OGFilter.Add( true, 'name', 'contains', 'calendar');
    var stav = OGFilter.AddBracket( true);
    OGFilter.Add( status, false, 'status', '=', 'New');
    OGFilter.Add( status, false, 'status', '=', 'For testing');
    OGFilter.Add( status, false, 'status', '=', 'To provide more information');

    //applies the filter
    OGFilter.Run();


    The resulting filter block looks after clicking like this:

     Filtr displays records, that contain in column Name value 'calendar' and at the same time have in column Status 'New', 'For testing' or 'To provide more information'.

    Filter on a button 3

    The following example creates a filter displaying records only from certain child classes of the class in which we are filtering. In case of more complex class hierarchy (child class has also child classes) we can e.g. filter records from one child class except for records belonging to a certain child class of this child class.

    // Displays records only from the child class All applications but not from the its child class System applications

    //clears possible existing filter
    OGFilter.Clear();

    // sets the filter to the requested values
    OGFilter.Add( true, '', '=', 'all-applications');
    OGFilter.Add( true, '', '!=', 'system-application');

    //applies the filter
    OGFilter.Run();

    The resulting filter block looks after clicking like this:

     

    Filter at displaying list of records

    The following example applies filter when displaying class/query list of records displaying only records with value in column 'To' that is greater than or equal to current date. The user can then see only current records, not that ones relating to past activities.

    Filter will be applied only at the first access to the page Datas.aspx (see condition !OGForm.Page.IsPostBack). This ensures that user can change the filter.

    The below script has to be placed in a class/query detail on tab Script - List of records.

    function OnLoad()
    {
    // Filters records with 'to' greater than or equal to today
      if ( !OGForm.Page.IsPostBack)
      {
        OGFilter.Clear();
        OGFilter.Add( true, 'to', 'in interval', 'today');
        OGFilter.Add( false, 'to', '>=', 'now');
        OGFilter.Run();
      }
    }

    The resulting filter block looks after clicking like this:

    If we want to enable user to save a link to records including filter from menu Favourites and apply this filter when using the link, it is necessary to use a condition in the script: ( !OGForm.QueryString.Exist('filter')). This will cause that if there is a filter defined in URL, the filter from the script will not be applied and filter from the URL will be used instead.

    function OnLoad()
    {
    // Filters records with 'to' greater than or equal to today
      if ( !OGForm.Page.IsPostBack)
      {
      if ( !OGForm.QueryString.Exist('filter'))
        {
           OGFilter.Clear();
           OGFilter.Add( true, 'to', 'in interval', 'today');
           OGFilter.Add( false, 'to', '>=', 'now');
           OGFilter.Run();
        }
      }
    }

     

    Filtering according to values in column Value from a referenced class (various classes)

     function OnLoad()
     {
       if ( !OGForm.Page.IsPostBack && !OGForm.QueryString.Exist('filter'))
       {
         OGFilter.Clear();
         OGFilter.Add( true, 'x-classlink-n', '=', '543-4');
         OGFilter.Run();
       }
     }

    Filtering according to child classes

    You can filter in the parent class also according to the child classes to which the records belong, Following two lines display example of a condition for record filtering. OGFilter.Add( true, '', '=', 'all-applications');
    OGFilter.Add( true, '', '!=', 'system-application');

×