JS Switch the Format of Date Query

  • Last update:December 28, 2020
  • I. Overview

    The date widget in FineReport can only select a specific date in the order of year-month-day. However, if you are to query a daily, weekly or monthly report, in which the date format is a fixed,  it is obviously troublesome to use the default order of year-month-day.

    We can use JS code to switch the format for date query:

    • For daily report, use the default date query format: year-month-day

    image.png

    • For weekly Report, only select certain days in a month.

    image (1).png

    • For monthly report, only select year and month.

    image (2).png

    II. Example

    2.1 Add widget

    Add three buttons, four date widgets, a label widget, and a query button,

    Set attributes of widgets:

    Stack the three date widgets, as shown below:

    image (3).png


    2.2 Set widget default values

    For widget start_day and start, the default value is formula: today().

    For widget start_week, the default value is formula: DATEINWEEK(today(),1).

    For widget start_month, the default value is formula: DATEINMONTH(today()-1,1).

    2.3 Add event

    Add Click events to buttons.

    JS code for button Daily Report:

    _g().parameterEl.getWidgetByName('rp').setValue("day");
    $("div[widgetname='START_MONTH']").hide();
    $("div[widgetname='START_DAY']").show();
    $("div[widgetname='START_WEEK']").hide();
    var start_day= _g().parameterEl.getWidgetByName('start_day').getValue();
    _g().parameterEl.getWidgetByName('start').setValue(start_day);
    _g().parameterCommit();

    JS code for button Weekly Report:

    _g().parameterEl.getWidgetByName('rp').setValue("week");
    $("div[widgetname='START_MONTH']").hide();
    $("div[widgetname='START_DAY']").hide();
    $("div[widgetname='START_WEEK']").show();
    var start_week= _g().parameterEl.getWidgetByName('start_week').getValue();
    _g().parameterEl.getWidgetByName('start').setValue(start_week);
    _g().parameterCommit();

    JS code for button Monthly Report:

    _g().parameterEl.getWidgetByName('rp').setValue("month");
    $("div[widgetname='START_MONTH']").show();
    $("div[widgetname='START_DAY']").hide();
    $("div[widgetname='START_WEEK']").hide();
    var start_month= _g().parameterEl.getWidgetByName('start_month').getValue();
    _g().parameterEl.getWidgetByName('start').setValue(start_month);
    _g().parameterCommit();

    JS code for button Search (i.e. the query button):

    var rp=_g().parameterEl.getWidgetByName('rp').getValue();
    if(rp=="day"){
    var start_day= _g().parameterEl.getWidgetByName('start_day').getValue();
    _g().parameterEl.getWidgetByName('start').setValue(start_day);
    }else if(rp=="week"){
    var start_week= _g().parameterEl.getWidgetByName('start_week').getValue();
    _g().parameterEl.getWidgetByName('start').setValue(start_week);
    }else{
    var start_month= _g().parameterEl.getWidgetByName('start_month').getValue();
    _g().parameterEl.getWidgetByName('start').setValue(start_month);
    }


    2.4 Report style

    1) In the parameter pane, the 3 widgets are stacked together so that there is only one date widget when displayed.

    2) Report content

    Add text to cell A2: The date you want to query is:

    Add formula to cell B2: $start

    The final effect is as follows:

    image (4).png

    2.5 Preview

    Save report, click Pagination Preview, the effect  is as follows:

    2.gif    

    Tips: Not support mobile terminal.

    III. Completed Template

    Attachment List


    Theme: Parameter
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy