2013-04-18 154 views
4

有没有可能取消选择一行而没有按住控制键,只能通过点击它?我的意思是,如果你点击一个已经选择的行,它应该取消选择,而不必按住控制键。Rowunselect没有按Ctrl +点击

回答

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; 
    } 
+0

如果我有多选数据表,我该怎么办? – leostiw 2013-04-18 08:07:15

+1

不,多重是不可能的,你必须使用控制键,你想象如何得到多个,如果不使用控制键:) – 2013-04-18 08:12:47

+3

@leostiw你可以真正避免使用RichFaces数据表组件启用“多键盘免费”选项的数据表组件。 [RichFaces DataTable - 多键盘免费](http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=extendedDataTable&sample=exTableSelection&skin=blueSky)问候, – 2013-04-18 08:36:53

-1

使用jquery切换功能。

$(selector).toggle(); 
+0

你能更具体的pleasa吗?我正在使用primefaces datatable顺便说一句。 – leostiw 2013-04-18 06:59:38

0

我得到了sollution。

我刚刚覆盖了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() 
    } 
    }, 

,如果你需要帮助,你可以给我一个信息。