コントロールキーを押さずに、クリックするだけで行の選択を解除する可能性はありますか? つまり、既に選択されている行をクリックすると、コントロール キーを押さなくても選択が解除されます。
2130 次
3 に答える
2
私は Primefaces 3.4.2 でテストしました: xhtml ページ:
<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);" />
豆:
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;
}
于 2013-04-18T07:44:26.670 に答える
1
私は解決策を得ました。
私は Primefaces.js をオーバーライドしました。実際には、Primefaces.Datatable の一部をコピーし、CtrlKey を使用して行の選択を解除する必要があるという条件を削除しました。
ここに例があります:
元の JavaScript の引用:
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()
}
},
この部分を次のように変更するだけです。
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()
}
},
助けが必要な場合は、私にメッセージを送ってください。
于 2016-08-09T17:39:59.687 に答える