JS Highlight title cell with hyperlink when mouse hovered

  • Last update:  2020-12-15
  • I. Overview

    1.1 Problem

    When there are hyperlink text in the heading row (often in column dynamic sorting), and we want them to be highlighted when the mouse is hovering on corresponding columns, how can we achieve that?

    1.gif


    1.2 Solution

    Through setting template loading end event, using JS to obtain cell ID, to set cell background to the corresponding cell.

    Note: Only support text in the same heading row.

    II. Example

    2.1 Report design

    Design a detailed report, and bind the dataset. Set hyperlink to some of the text in the heading row.

    image.png

    Click Template > Template Web Attributes > Pagination Preview, select set individually for the template. Add a loading end event here:

    $("td").mouseover(function(){ //Mouse over the cell event
    var id=$(this).attr("id"); //Get the id of the cell where the mouse is currently located
    var num=id.search("-"); //Get the index of the first occurrence of the "-" symbol in id
    var id1=id.substr(0,num).replace(/[^a-z]+/ig,""); //Split the letters in the id value, that is, the column number
    var id2=id.substr(num,id.length-num); //Substract id
    id=id1+"1"+id2; //Set id to the cell id of the list header of the cell where the mouse is located, 1 means the row of the column header
    if($('td[id^='+id+']').attr('class').indexOf('celink')!==-1) //Determine whether the column title contains a hyperlinked class
    {
    $('td[id^='+id+']').css({'background':'yellow'}); //Set the background color of the column header cell
    }
    });
    $("td").mouseleave(function(){ //Mouse leave the cell event
    var id=$(this).attr("id");
    var num=id.search("-");
    var id1=id.substr(0,num).replace(/[^a-z]+/ig,"");
    var id2=id.substr(num,id.length-num);
    id=id1+"1"+id2; //Set id to the cell id of the list header of the cell where the mouse is located, 1 means the row of the column header
    $('td[id^='+id+']').css({'background':'#e7ebf1'}); //Set the background color of the column header cell to the original background color
    });


    2.2 Preview effect

    Click save and then preview, we can see the effect as described above.

    1.gif

    III. Download template

    Attachment List


    Theme: Report Application
    • 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