Using jQuery to highlight a selected row of ASP.NET DataGrid data

It is easy to select the selected datagrid row, for example using toggleClass in the tr click event. But what is the best way to remove the highlight after selecting another line? Iterating over all rows to display them can be expensive for big data. I would be interested in the simplest solution, as well as the most productive.

Thanks,
Mike

+4
source share
3 answers

This method stores the active string in a variable. The $ at the beginning of the variable is just my own Hungarian designation for jQuery objects.

var $activeRow; $('#myGrid tr').click(function() { if ($activeRow) $activeRow.removeClass('active'); $activeRow = $(this).addClass('active'); }); 
+3
source

If you just want to find elements with toggledClass and disable this with jQuery:

 $('.toggledClass').removeClass('toggledClass'); 
+3
source

To improve performance, you can click on the selected element identifier in var (or an array for multiples), and then use this var / iterate over this array when disabling classes.

0
source

Source: https://habr.com/ru/post/1277314/


All Articles