【问题标题】:Rowunselect without ctrl+clickRowunselect 没有 ctrl+单击
【发布时间】:2013-04-11 04:16:28
【问题描述】:

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

【问题讨论】:

    标签: javascript ajax jsf primefaces


    【解决方案1】:

    我已经使用 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;
        }
    

    【讨论】:

    • 如果我有一个多选数据表,我该怎么做?
    • 不,多个是不可能的,你必须使用控制键,你想象如果不使用控制键如何获得多个:)
    • @leostiw 您可以通过使用启用了“多个无键盘”选项的 RichFaces 数据表组件来真正避免使用 Control-Key。 RichFaces DataTable - Multiple Keyboard-Free 问候,
    【解决方案2】:

    我得到了解决方案。

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

    如果您需要帮助,可以给我发消息。

    【讨论】:

      【解决方案3】:

      使用 jquery 切换功能。

      $(selector).toggle();
      

      【讨论】:

      • 您能说得更具体些吗?顺便说一句,我正在使用 primefaces 数据表。
      猜你喜欢
      • 2018-07-22
      • 2015-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-27
      • 2011-05-22
      • 1970-01-01
      • 2023-04-02
      相关资源
      最近更新 更多