Jquery datatable - Selected row hightlight issue
Jquery datatable - Selected row hightlight issue
jquerydatatable
Posts: 5Questions: 0Answers: 0
In my datatable, getting result from search button action. So first search results selected row hightlight working good , but again search those results are not highlighting .why second time selected row high light is not working good ? Please advise...
This demo not simulated the issue which i mention , but similar way the works datatable..
[1]: http://jsfiddle.net/rwPFx/34/
$('#products1 tbody tr').live("click", function () {
if ($(this).hasClass('selected1')) $(this).removeClass('selected1');
else
{
$(this).siblings('.selected1').removeClass('selected1');
$(this).addClass('selected1');
}
$("#dialog-form").data('rows', oTable.fnGetData( this ));
});
This demo not simulated the issue which i mention , but similar way the works datatable..
[1]: http://jsfiddle.net/rwPFx/34/
$('#products1 tbody tr').live("click", function () {
if ($(this).hasClass('selected1')) $(this).removeClass('selected1');
else
{
$(this).siblings('.selected1').removeClass('selected1');
$(this).addClass('selected1');
}
$("#dialog-form").data('rows', oTable.fnGetData( this ));
});
This discussion has been closed.
Replies
Thanks for the link to the JSFiddle page. The problem that you are encountering is that the event handler is being added to the page multiple times - every time the search button is clicked in fact.
The result is that the click handler will fire multiple times. So for example, if you click search once, the event handlers is added once. Click it again and the event handler is there twice. Then if you click a row in the table, it gets selected by the first event handler, and then deselected by the second!
So you just want to attach the event handler once:
http://jsfiddle.net/rwPFx/39/
Regards,
Allan
I'm afraid I don't quite understand - sorry. One the second click of the "Search" button, nothing will change in the example you linked to since the data used for the table is the same.
Allan