JS Change the Styles of Cell or Row where Mouse Hover

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

    When designing a dashboard, you may encounter such a requirement: when the mouse moves over the report block, highlight the current cell or current row where the mouse hovers.

    However, due to the particularity of dashboard, the requirement cannot be realized by adding a loading end event which is usually appied in a normal report. How do we achieve this effect? Results as shown below:

    1606381867437323.gif

    II. Example 1 - Change the Styles of Cell

    2.1 New template

    Create a new dashboard, add dataset ds1, and the SQL statement is:

    SELECT * FROM Product

    Add report block report0 and drag into the data columns of ds1, as shown in the following figure:

    1606381920572652.png


    2.2 Add event

    Select report0 and add an After Initialization event, as shown in the following figure:

    1606381957334754.png

    The JS code is as follows:

    setTimeout(function() {
      //When the mouse passes
      $(".x-table.REPORT0table td").mousemove(function() {
          //The font color of the cell is red
          $(this).css("color", "red");
          //The background of the cell is blue
          $(this).css("background-color", "blue");
          //Bold font of the cell
          $(this).css("font-weight", "bold");
          //Add an underline to the cell
          $(this).css("text-decoration", "underline");
          //The font of the whole row: 11px
          $(this).find("td").css("font-size", "11px");
      });
      //When the mouse is clicked
      $(".x-table.REPORT0table td").mousedown(function() {
          //The font color of the cell is yellow
          $(this).css("color", "yellow");
          //The background of the cell is black
          $(this).css("background-color", "black");
          //Bold font of the cell
          $(this).css("font-weight", "bold");
          //Add an overline to the cell
          $(this).css("text-decoration", "overline");
          //The font of the whole row: 13px
          $(this).find("td").css("font-size", "13px");
      }); 
      //Mouse left
      $(".x-table.REPORT0table td").mouseout(function() {
          //The font color of the cell is black
          $(this).css("color", "black");
          //The background of the cell is white
          $(this).css("background-color", "white");
          //The font of the cell is normal
          $(this).css("font-weight", "normal");
          //The text in the cell is not underlined or overlined
          $(this).css("text-decoration", "none");
          //The font of the whole row: 9px
          $(this).find("td").css("font-size", "9px");
      });
    }, 100);


    2.3 Template preview

    Save the template, and the preview effect is as shown in the figure below:

    1606381994478093.png

    III. Example 2 - Change the Style of Row

    3.1 Modify the template

    Add report block report1 and drag into data columns of ds1, as shown in the figure below:

    1606382027226767.png


    3.2 Add event

    Select report1 and add an After Initialization event, as shown below:

    1606382069418237.png

    The JS code is as follows:

    setTimeout(function() {
      //When the mouse passes
      $(".x-table.REPORT1table tr").mousemove(function() {
        //The font color of the whole row: red
        $(this).css("color", "red");
        //The background color of the whole row: blue
        $(this).css("background-color", "blue");
        //Bold font in the whole row
        $(this).css("font-weight", "bold");
        //Add an underline to text in the whole row
        $(this).css("text-decoration", "underline");
        //The font of the whole row: 11px
        $(this).find("td").css("font-size", "11px");
      });
      
      //When the mouse is clicked
      $(".x-table.REPORT1table tr").mousedown(function() {
        //The font color of the whole row: yellow
        $(this).css("color", "yellow");
        //The background color of the whole row: black
        $(this).css("background-color", "black");
        //Bold font in the whole row
        $(this).css("font-weight", "bold");
        //Add an overline to the text in the whole row
        $(this).css("text-decoration", "overline");
        //The font of the whole row: 13px
        $(this).find("td").css("font-size", "13px");
      });
      
      //Mouse left
      $(".x-table.REPORT1table tr").mouseout(function() {
        //The font color of the whole row: black
        $(this).css("color", "black");
        //The background color of the whole row: white
        $(this).css("background-color", "white");
        //Normal font in the whole row
        $(this).css("font-weight", "normal");
        //The text is nor underlined or overlined
        $(this).css("text-decoration", "none");
        //The font of the whole row: 9px
        $(this).find("td").css("font-size", "9px");
      });
    }, 100);


    3.3 Template preview

    Save the template, and the preview effect is shown in the figure below:

    1606382093749050.png

    Note: Mobile terminal is not supported.

    IV. Completed Template

    Attachment List


    Theme: FineVis Data Visualization
    • 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