leostiw leostiw - 3 months ago 27
Ajax Question

Rowunselect without ctrl+click

Is there a possibility to unselect a row without to hold the control key,only by clickin on it? By that I mean, if you click on an already selected row, it should unselect, without having to hold the control key.

Answer

I have tested with Primefaces 3.4.2: xhtml page:

<script type="text/javascript">
                function test(xhr, status, args){
                    if(args.unselecttest % 2 == 1){
                        stest.unselectAllRows();
                    }
                }
            </script>
<p:dataTable widgetVar="stest" selectionMode="single" selection="#{tabview.car}"
<p:ajax event="rowSelect" oncomplete="test(xhr, status, args);" />

Bean:

private int count = 0;

    public Car getCar() {
        return car;
    }

    public void setCar(Car car) {
        if (car.equals(this.car)) {
            count++;
            RequestContext reqCtx = RequestContext.getCurrentInstance();
            reqCtx.addCallbackParam("unselecttest", count);
        } else {
            count = 0;
        }
        this.car = car;
    }