JS Dynamic star rating

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

    1.1 Problem

    In the report application, we may use graphics to display the effects such as scoring. In data entry reports, how to achieve the dynamic star scoring effect?


    1.2 Solution

    We can use the relationship between the tables, rows, columns, and cells of the report page, and together with events such as mouse movement, sliding out, and clicking.

    1.gif

    II. Example

    2.1 Prepare the picture

    First of all, we need to prepare the star pictures of selected and unselected effect, as shown below:

    Selected: staron.png

    Unselected: staroff.png

    Download the picture, create a new iamge folder in the %FR_HOME%\webapps\webroot\help\picture; and place the picture in the folder %FR_HOME%\webapps\webroot\help\picture\image.

    4.png


    2.2 Design the template

    Create a new workbook, the template style is as follows, and the cells are all set to center aligned.

    Among them, B2-F2 is the scoring area, and G2 shows the score.

    5.png


    2.3 Modify the cell style and shape of the scoring area

    In order to display the status of no rating when the cell is initialized, we add a background image for the B2:F2 cell, namely staroff.png, as shown in Figure 1:

    6.png

    Set the formula form of cell B2:F2, enter the formula "", as shown in Figure 2:

    7.png


    2.4 Data entry attributes

    Click [template]-[template web attributes]-[data entry settings] to add a loading end event to the template, as shown below:

    8.png

    $("td[row=1]").mouseover(function(){
    //row=1 means the second row
    var $td=$(this);
    var col=parseInt($td.attr('col'));
    if(col>0&&col<6){
    for(var i=1;i<=col;i++){
    $("td[row=1][col="+i+"]").css('background',"url(/webroot/help/picture/image/staron.png) no-repeat 50% 50%");
    };
    for(var i=col+1;i<6;i++){
    $("td[row=1][col="+i+"]").css('background',"url(/webroot/help/picture/image/staroff.png) no-repeat 50% 50%");
    };
    }
    }).mouseout(function(){
    var $td=$(this);
    var col=parseInt($td.attr('col'));
    if(col>0&&col<6){
        for(var i=1;i<6;i++){
    $("td[row=1][col="+i+"]").css('background',"url(/webroot/help/picture/image/staroff.png) no-repeat 50% 50%");
    };
    var score=contentPane.curLGP.getCellValue('G2')*1;
    if(score>=1){
    for(var i=1;i<=score;i++){
       $("td[row=1][col="+i+"]").css('background',"url(/webroot/help/picture/image/staron.png) no-repeat 50% 50%");
    };
    }
    }
    }).click(function(){
    var $td=$(this);
    var col=parseInt($td.attr('col'));
    if(col>0&&col<6){
    var score=parseInt($td.attr('cv'));
    contentPane.setCellValue('G2',null,score);
    }
    })
    Show Code


    2.5 Preview effect

    Save the template and click [Data entry preview]:

    9.gif

    III. Download template

    Attachment List


    Theme: Data Entry
    • Helpful
    • Not helpful
    • Only read

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

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

    不再提示

    9s后關閉

    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