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.
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;
}
I got the sollution.
I just overrired the primefaces.js, actually, i just copy the part of Primefaces.Datatable and just remove the condition that says it was required to unselect the row using CtrlKey.
Here the example:
The Original javascript quote:
onRowClick: function (e, d, a) {
if ($(e.target) .is('td,span:not(.ui-c)')) {
var g = $(d),
c = g.hasClass('ui-state-highlight'),
f = e.metaKey || e.ctrlKey,
b = e.shiftKey;
if (c && f) {
this.unselectRow(g, a)
} else {
if (this.isSingleSelection() || (this.isMultipleSelection() && e && !f && !b && this.cfg.rowSelectMode === 'new')) {
this.unselectAllRows()
}
if (this.isMultipleSelection() && e && e.shiftKey) {
this.selectRowsInRange(g)
} else {
this.originRowIndex = g.index();
this.cursorIndex = null;
this.selectRow(g, a)
}
}
PrimeFaces.clearSelection()
}
},
You just change this part to this:
onRowClick: function (e, d, a) {
if ($(e.target) .is('td,span:not(.ui-c)')) {
var g = $(d),
c = g.hasClass('ui-state-highlight'),
// I changed it to true
f = true;
b = e.shiftKey;
if (c && f) {
this.unselectRow(g, a)
} else {
if (this.isSingleSelection() || (this.isMultipleSelection() && e && !f && !b && this.cfg.rowSelectMode === 'new')) {
this.unselectAllRows()
}
if (this.isMultipleSelection() && e && e.shiftKey) {
this.selectRowsInRange(g)
} else {
this.originRowIndex = g.index();
this.cursorIndex = null;
this.selectRow(g, a)
}
}
PrimeFaces.clearSelection()
}
},
if you need some help, you can send me a message.
使用jQuery切换功能。
$(selector).toggle();
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.