简体   繁体   中英

detect when user check or uncheck row on client side in primefaces datatable

I use this row editing primefaces datatable and I added the multiple selection feature through this example

then I want to detect on client side when the user check or uncheck one row and the number of rows checked at each change

I tried a many ways with firebug .... but no result

here is one of my essays (just for testing):

$(function(){                       
                $('.ui-chkbox-box.ui-widget.ui-corner-all.ui-state-default').mousemove(function(){

                    if(('.ui-chkbox-box.ui-widget.ui-corner-all.ui-state-default').hasClass('ui-state-active'))
                        alert('show');
                });

do you have any idea

If you just want know when a user clicked a checkbox that is located in a datatable, you can use this code to listen for the click and verify if it is checked or not:

jQuery(".ui-chkbox").click(function () {
    if(jQuery(this).find("span").first().hasClass("ui-icon-check"))
        alert("unchecked");            
    else
        alert("checked");
}

Notice that the if clause is inverted, it happens because this function will be called before primefaces adds the class "ui-icon-check" to the div.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM