4

是否有可能在不按住控制键的情况下取消选择一行,只需单击它?我的意思是,如果您单击已选择的行,它应该取消选择,而不必按住控制键。

4

3 回答 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 回答
-1

使用 jquery 切换功能。

$(selector).toggle();
于 2013-04-18T06:56:31.733 回答