DataTable: How to catch selection event with JavaScript?

UI Components for JSF
dasago
Posts: 32
Joined: 26 May 2011, 13:01

02 Nov 2011, 11:09

Did you find out how it works with Version 3?
Primefaces 4.0
Mojarra 2.1.21
JBoss As 7.0 Final
Internet explorer 9

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

02 Nov 2011, 12:20

In 3.0 you can use

Code: Select all

<p:ajax event="rowSelect" .... onclick="handleCustomRowSelect(); return false;" />
with callback handler, but p:ajax doesn't generate an optimal code - p:ajax was designed to be used for ajax interactions. I would propose to use pe:javascript from PrimeFaces extensions project http://code.google.com/p/primefaces-extensions/ (momentan you should build it from source, but i will be available in Maven central repo).

Code: Select all

<pe:javascript event="rowSelect" execute="handleCustomRowSelect();" />
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

dasago
Posts: 32
Joined: 26 May 2011, 13:01

02 Nov 2011, 17:04

Hi Oleg,

thx for your fast reply.

I want to remove the ui-state-highlight class for selected rows.

With this code it works fine.. but i think there is still a better solution. Do you know one?

<p:ajax event="rowSelect" oncomplete="removeHighlight();" />

JS:
function removeHighlight(){
var elm = $("#formId\\:datatableId tr");
elm.removeClass('ui-state-highlight');
}

$(document).ready(function(){
removeHighlight();
});

I don't want to override the datatable.js of primefaces.
Primefaces 4.0
Mojarra 2.1.21
JBoss As 7.0 Final
Internet explorer 9

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

02 Nov 2011, 18:03

Hi,

Why do you remove it via JavaScript in oncomplete? Can you not overwrite .ui-state-highlight for datatable rows in CSS?
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

dasago
Posts: 32
Joined: 26 May 2011, 13:01

02 Nov 2011, 18:49

The problem is, that i have even and odd rows. If i overwrite the css it doesn't work with even and odd...
Primefaces 4.0
Mojarra 2.1.21
JBoss As 7.0 Final
Internet explorer 9

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests