【问题标题】:Flexigrid: selection of rows to survive refreshFlexigrid:选择行以在刷新后存活
【发布时间】:2010-10-31 16:26:01
【问题描述】:

我在一个项目中使用 flexigrid,我希望能够在网格刷新后保留选定的行。我在 flexigrid 讨论板上问了同样的问题,我得到了这个答案:

添加一个点击处理程序,如果选择行的行ID,则保存ID。刷新完成后,再次选择该行(如果仍然存在)

不知道该怎么做,我什至不知道函数会是什么样子,所以我没有任何代码可以开始。

如果有人能指出我正确的方向,将不胜感激。

谢谢,

克里斯蒂安。

【问题讨论】:

    标签: javascript jquery flexigrid


    【解决方案1】:

    Flexigrid 将一个名为trSelected 的类添加到选定的行,因此每当网格上发生单击事件时,您只需查找所有选定的行并以某种方式保存它们。下面是您可以执行的操作的一个简单示例:

    var selectedRows = new Array();
    
    $('#myGrid').click(function() {
        selectedRows = new Array();
    
        $(this).find('tr.trSelected').each(function(i, selectedRow) {
            selectedRows.push($(selectedRow));        
        });
    });
    

    【讨论】:

      【解决方案2】:

      我做了一些小代码来保持分页和刷新期间的多选。

          $("#searchPhonoList").flexigrid($.extend({}, flexigridAttrs, {
              url: './rest/phono/search',
              preProcess: formatSearchPhonoResults,
              onSuccess: successSearchPhono,
              onSubmit: submit,
              method: 'GET',
              dataType: 'json',
              colModel : [
                  {display: 'titre', name: 'titre_brut', width : 240,  sortable : true, align: 'left'},
                  {display: 'version', name: 'version_brut', width : 60,  sortable : true, align: 'left'}
              ],
              height: "auto",
              sortname: "score",
              sortorder: "desc",
              showTableToggleBtn: false,
              showToggleBtn: false,
              singleSelect: false,
              onToggleCol: false,
              usepager: true, 
              title: "Liste des candidats",
              resizable: true,
              rp:20,
              useRp: true
          }));  
      
          var searchPhonoListSelection = new Array();
      
          $('#searchPhonoList').click(function(event){
      
              $(' tbody tr', this).each( function(){
                  var id = $(this).attr('id').substr(3);
                  if ( searchPhonoListSelection.indexOf(id) != -1 ) {
                      searchPhonoListSelection.splice(searchPhonoListSelection.indexOf(id), 1);
                  }
              });
      
              $('.trSelected', this).each( function(){
                  var id = $(this).attr('id').substr(3);
                  if ( searchPhonoListSelection.indexOf(id) == -1  ) {
                      searchPhonoListSelection.push(id);
                  }
              });
          });
      
      
          function successSearchPhono() {
              $("#searchPhonoList tbody tr").each( function() {
                  var id = $(this).attr('id').substr(3);
                  if ( searchPhonoListSelection.indexOf(id) != -1 ) {
                      $(this).addClass("trSelected");
                  }
              });
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-03-09
        相关资源
        最近更新 更多