1: //mouseover event handler
2: function cellHover(e)
3: { 4: //$(this) is the current hover cell jQuery Object.
5: //$dataRows is a private jGuery variable holding all data rows
6: //$column is a jQuery local variable holds all cells on the same column (having same cellIndex) as current cell
7:
8: //get all cells in the current row including current hovering cell.
9: var $cells = $(this).siblings().andSelf();
10:
11: //Accessing additional data sent to the event handler.
12: var index = e.data.cellIndex+1;
13:
14: //Equation to select cells of the same column.
15: var eq = ':nth-child('+index+')'; 16:
17: //Column Cells
18: var $column = $dataRows.children(eq);
19:
20: //Attache rowHoverClass to each cell.
21: $cells.each(function(){ 22: if(notEmptyOrNull(opts.rowHoverClass) && !$(this).hasClass(opts.rowHoverClass))
23: $(this).addClass(opts.rowHoverClass);
24: });
25:
26: //Attache columnHoverClass to each cell on the column.
27: $column.each(function(){ 28: if(notEmptyOrNull(opts.columnHoverClass) && !$(this).hasClass(opts.columnHoverClass))
29: $(this).addClass(opts.columnHoverClass);
30: });
31:
32: //If cellHoverClass Applied, remove columnHoverClass from current hover cell.
33: if(notEmptyOrNull(opts.cellHoverClass) && !$(this).hasClass(opts.cellHoverClass)){ 34: $(this).removeClass(opts.columnHoverClass);
35: $(this).addClass(opts.cellHoverClass);
36: }
37: };
38: //mouseout event handler
39: function cellOut(e)
40: { 41: //$(this) is the current hover cell jQuery Object.
42: //$dataRows is a private jGuery variable holding all data rows
43: //$column is a jQuery local variable holds all cells on the same column (having same cellIndex) as current cell
44:
45: //get all cells in the current row including current hovering cell.
46: var $cells = $(this).siblings().andSelf();
47:
48: //Accessing additional data sent to the event handler.
49: var index = e.data.cellIndex+1;
50:
51: //Equation to select cells of the same column.
52: var eq = ':nth-child('+index+')'; 53:
54: //Column Cells
55: var $column = $dataRows.children(eq);
56:
57: //Remove rowHoverClass from each cell in the current row.
58: $cells.each(function(){ 59: if(notEmptyOrNull(opts.rowHoverClass) && $(this).hasClass(opts.rowHoverClass))
60: $(this).removeClass(opts.rowHoverClass);
61: });
62:
63: //Remove columnHoverClass from each cell in the current column.
64: $column.each(function(){ 65: if(notEmptyOrNull(opts.columnHoverClass) && $(this).hasClass(opts.columnHoverClass))
66: $(this).removeClass(opts.columnHoverClass);
67: });
68:
69: //Remove cellHoverClass current cell.
70: if(notEmptyOrNull(opts.cellHoverClass) && $(this).hasClass(opts.cellHoverClass))
71: $(this).removeClass(opts.cellHoverClass);
72: };
73: //click event handler
74: function cellClick(e)
75: { 76: //$(this) is the current hover cell jQuery Object.
77: //$dataRows is a private jGuery variable holding all data rows
78:
79: //Remove all attached css classes to be ready to apply rowSelectClass
80: $dataRows.each(function(){ 81: $dataRows.children().each(function(){ 82: if(notEmptyOrNull(opts.rowSelectClass) && $(this).hasClass(opts.rowSelectClass))
83: $(this).removeClass(opts.rowSelectClass);
84:
85: if(notEmptyOrNull(opts.cellHoverClass) && $(this).hasClass(opts.cellHoverClass))
86: $(this).removeClass(opts.cellHoverClass);
87:
88: if(notEmptyOrNull(opts.cellSelectClass) && $(this).hasClass(opts.cellSelectClass))
89: $(this).removeClass(opts.cellSelectClass);
90: });
91: });
92:
93: var $cells = $(this).siblings().andSelf();
94:
95: //Attache rowSelectClass to current selected row.
96: $cells.each(function(){ 97: if(notEmptyOrNull(opts.rowSelectClass) && !$(this).hasClass(opts.rowSelectClass))
98: $(this).addClass(opts.rowSelectClass);
99: });
100:
101: if(notEmptyOrNull(opts.cellSelectClass) && !$(this).hasClass(opts.cellSelectClass)){ 102: $(this).removeClass(opts.rowSelectClass);
103: $(this).removeClass(opts.columnHoverClass);
104: $(this).removeClass(opts.columnSelectClass);
105: $(this).addClass(opts.cellSelectClass);
106: }
107: };
108:
109: function notEmptyOrNull(value){ 110: return value != '' && value != null;
111: };