Right now the row gets highlighted on hovering but I also want the row to be highlighted with a different color after it has been selected.
Please suggest a solution to this.
Hello,
You can use the rowClick function to achieve the highlighting effect. I've added a jsfiddle that @Tabalinas created showing how to highlight a row.
rowClick: function(args) {
var $row = this.rowByItem(args.item);
$row.toggleClass("highlight");
},
@soul3lade, Thank you for the answer.
@himanshu0a, please let us know if this is what you were looking for.
Yes this is the correct answer and this is exactly i was looking for.
Thanks @soul3lade
The above solution did not work for me, I had to set the background color for each cell in the row:
rowClick: function(args) {
if ( selectedRow ) { selectedRow.children('.jsgrid-cell').css('background-color', ''); }
var $row = this.rowByItem(args.item);
$row.children('.jsgrid-cell').css('background-color','#F7B64B');
selectedRow = $row;
},
I changed @soul3lade 's fiddle a little bit (changed the CSS) to make it working (it seemed it was not working).
Se voc锚 veio em busca de uma solu莽茫o na qual apenas 1 linha 茅 selecionada e que tamb茅m desseleciona a mesma linha, aqui est谩 a solu莽茫o:
If you came looking for a solution in which only 1 line is selected and which also deselects the same line, here is the solution:
selectedVal = null;
$(document).ready(function(){
jsGrid.Grid.prototype.rowByIndex = function(arg) {
//this._content.find("tr")[arg] returns a DOM element instead of a jQuery object
//Pass the DOM element to the find method to get a jQuery object representing it
return this._content.find(this._content.find("tr")[arg]);
};
});
rowClick: function (args) {
selectedVal = args.item;
let $row = this.rowByItem(args.item);
if ($row.hasClass("highlight") === false) {
//Deseleciona todas as linhas
for (let i = 0; i < this.data.length; i++) {
this.rowByIndex(i).removeClass("highlight");
}
$row.toggleClass("highlight");
} else {
selectedVal = null;
$row.toggleClass("highlight");
}
console.log(selectedVal);
}