Javascript Rowunselect不带ctrl+;点击
是否可以在不按住控制键的情况下取消选中某一行,只需单击该行即可?我的意思是,如果您单击已选择的行,它应该取消选择,而不必按住control键。使用jquery切换功能Javascript Rowunselect不带ctrl+;点击,javascript,ajax,jsf,primefaces,Javascript,Ajax,Jsf,Primefaces,是否可以在不按住控制键的情况下取消选中某一行,只需单击该行即可?我的意思是,如果您单击已选择的行,它应该取消选择,而不必按住control键。使用jquery切换功能 $(selector).toggle(); 我已使用Primefaces 3.4.2进行了测试: xhtml页面: <script type="text/javascript"> function test(xhr, status, args){
$(selector).toggle();
我已使用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);" />
我得到了解决方案
我只是过度使用了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()
}
},
如果您需要帮助,可以给我发个信息。您能说得更具体一点吗?顺便说一句,我使用的是primefaces datatable。如果我有一个多重选择datatable,我该怎么做?不,多重是不可能的,你必须使用控制键,你可以想象如果不使用控制键如何获得多重:)@leostiw你可以使用启用了“多键盘自由”选项的RichFaces datatable组件来避免控制键。当做
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()
}
},