简体   繁体   English

JQuery突出显示表中的行和列

[英]JQuery Highlight Row and Column in table

I want to add to my site table with highlighting row and column, but I have troubles with column highlighting.我想通过突出显示行和列添加到我的站点表中,但是我在突出显示列时遇到了麻烦。 This is my table.这是我的桌子。 This is online courses and a full the table with names such as Homework1, HW2 and etc.这是在线课程和完整的表格,其中包含 Homework1、HW2 等名称。

 %if len(students) > 0: <div class="grades"> <table class="grade-table"> <% templateSummary = students[0]['grade_summary'] %> <thead> <tr class = "table-header"> <!— Header Row —> %for section in templateSummary['section_breakdown']: //...... <th title="${tooltip_str}"><div class="assignment-label">${section['label']}</div></th> %endfor <th title="${_('Total')}"><div class="assignment-label">${_('Total')}</div></th> </tr> </thead> <%def name="percent_data(fraction, label)"> //.... <td class="${data_class}" data-percent="${fraction}" title="${label}">${ "{0:.0f}".format( 100 * fraction ) }</td> </%def> <tbody> %for student in students: <tr class="table-row"> %for section in student['grade_summary']['section_breakdown']: ${percent_data( section['percent'], section['detail'] )} %endfor ${percent_data( student['grade_summary']['percent'], _('Total'))} </tr> %endfor </tbody> </table>

This is JQuery.这是 JQuery。 So in highlightRow() is making the magic with row, but I don't understand, to add highlightColumn() and "$element.find('tr').bind('mouseover', highlightColumn);"所以在 highlightRow() 中使用 row 创造了魔法,但我不明白,添加 highlightColumn() 和 "$element.find('tr').bind('mouseover', highlightColumn);" or to add in the function highlightRow() code for column.或为列添加函数 highlightRow() 代码。

 var Gradebook = function($element) { "use strict"; var $body = $('body'); var $grades = $element.find('.grades'); var $studentTable = $element.find('.student-table'); var $gradeTable = $element.find('.grade-table'); var $search = $element.find('.student-search-field'); var $leftShadow = $('<div class="left-shadow"></div>'); var $rightShadow = $('<div class="right-shadow"></div>'); var tableHeight = $gradeTable.height(); var maxScroll = $gradeTable.width() - $grades.width(); var mouseOrigin; var tableOrigin; var startDrag = function(e) { mouseOrigin = e.pageX; tableOrigin = $gradeTable.position().left; $body.addClass('no-select'); $body.bind('mousemove', onDragTable); $body.bind('mouseup', stopDrag); }; var highlightRow = function() { $element.find('.highlight').removeClass('highlight'); var index = $(this).index(); $studentTable.find('tr').eq(index + 1).addClass('highlight'); $gradeTable.find('tr').eq(index + 1).addClass('highlight'); }; $leftShadow.css('height', tableHeight + 'px'); $grades.append($leftShadow).append($rightShadow); setShadows(0); $grades.css('height', tableHeight); $gradeTable.bind('mousedown', startDrag); $element.find('tr').bind('mouseover', highlightRow); $search.bind('keyup', filter); $(window).bind('resize', onResizeTable); };

It should be something like this:它应该是这样的:

$element.find('td').bind('mouseover', highlightColumn);

var highlightColumn = function() {
     //remove all highlights
     //not sure if it should be here may be it should happen before both highlightRow and highlightColumn function calls
     $element.find('.highlight').removeClass('highlight');

     var columnIndex = $(this).index(); //this should be td in this case

     $studentTable.find('tr td:eq(' + columnIndex + ')').addClass('highlight');
     $gradeTable.find('tr td:eq(' + columnIndex + ')').addClass('highlight');
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM