2011-10-24 56 views
1

我已经创建了一个基于此 example的过滤器工具栏。我有一个奇怪的问题;这仅适用于设置了萤火虫断点时,否则,下拉菜单仅显示“全部”。网格设置为数据类型:'json',loadonce:true。还有一点;这个网格也有一个子网格。任何想法如何让这个工作?我宣布了网后Jqgrid搜索工具栏过滤器与Json的唯一下拉列表

grid = $("#dealsgrid"), 
getUniqueNames = function(columnName) { 
     var texts = grid.jqGrid('getCol', columnName); 
     var uniqueTexts = []; 
     var textsLength = grid.jqGrid('getGridParam','data'); 
     var text, textsMap = {}, i; 
     for (i = 0; i < textsLength; i++) { 
      text = texts[i]; 
      if (text !== undefined && textsMap[text] === undefined) { 
      // to test whether the texts is unique we place it in the map. 
      textsMap[text] = true; 
      uniqueTexts.push(text); 
      } 
     } 
     return uniqueTexts; 
    }, 
buildSearchSelect = function(uniqueNames) { 
     var values = ":All"; 
     $.each(uniqueNames, function() { 
      values += ";" + this + ":" + this; 
     }); 
     return values; 
    }, 
setSearchSelect = function(columnName) { 
     grid.jqGrid(
     'setColProp', 
     columnName, 
     { 
      stype : 'select', 
      searchoptions : { 
       value : buildSearchSelect(getUniqueNames(columnName)), 
       sopt : [ 'eq' ] 
      } 
     }); 
}; 

,我列模型是这样的:

colModel:[ 
       {name:'CM',index:'CM', width:50,editable:false}, 
       {name:'DealNo',index:'DealNo',width:75,editable:false,editoptions:{readonly:true, size:10},search:true, stype:'text', searchoptions: { sopt: ['eq']}}, 
       {name:'KeyDate',index:'KeyDate',width:100, search:false, align:"right",formatter:'date'}, 
       {name:'VendorNo',index:'VendorNo', width:75,search:true}, 
       {name:'VendorName',index:'VendorName', width:100,search:true}, 
       {name:'ItemQty',index:'ItemQty', width:75,search:false},{name:'StartDate',index:'StartDate',width:100,align:"right",formatter:'date',search:false}, 
       {name:'EndDate',index:'EndDate',width:100, align:"right",formatter:'date',search:false}, 
       {name:'ActiveStartDate',index:'ActiveStartDate',width:100, align:"right",formatter:'date',search:false, sorttype:"date", editable:true,editoptions:{size:10}},     {name:'ActiveEndDate',index:'ActiveEndDate',width:100,align:"right",formatter:'date',search:false, sorttype:"date",editable:true,editoptions:{size:10}},    
       {name:'DealType',index:'DealType', width:75,search:false} 

      ], 

最后,我呼吁创建filterToolBar和填充下拉

 setSearchSelect('CM'); 
     grid.jqGrid('setColProp', 'Name', { 
     searchoptions : { 
      sopt : [ 'cn' ], 
      dataInit : function(elem) { 
       $(elem).autocomplete({ 
        source : getUniqueNames('Name'), 
        delay : 0, 
        minLength : 0 
       }); 
      } 
     } 

    }); 
    grid.jqGrid('filterToolbar', { 
     stringResult : true, 
     searchOnEnter : true, 
     defaultSearch : "eq" 
    }); 

任何建议,不胜感激。 谢谢

+0

请问您可以用jsfiddle重现您的问题,以便我们可以看一看。我已经创建了一个适合您的资源(css和js) - http://jsfiddle.net/yTX3P/1/不要忘记保存它。 –

+0

@Martijn B我的代码可在[链接](http://jsfiddle.net/yTX3P/4/embedded/result/) – Heather

+0

您的示例不会重现该问题。没有可用的数据。我无法以这种方式帮助你。你可以尝试的是从getUniqueNames方法返回uniqueTexts的断点,并检查哪些值被返回。如果这是空的,你必须关注getUniqueNames方法。 –

回答

1

现在我们知道你的函数正在返回一些东西(如果你在其上放置了一个断点),现在删除了我的旧回答。难道你的网格在getUniqueNames被调用之前还没有加载数据?这解释了如果你在它上面放置一个断点,它有更多的时间在调用getUniqueNames之前加载数据。

所以,如果你在gridComplete中调用setSearchSelect,或者甚至可能loadComplete它应该没问题。也许你甚至必须将网格的异步属性设置为false。我需要用我自己的代码来检查一下,所以我可以为你提供一个例子。我会在早上做第一件事。同时你可以根据上面的信息做一些调整。

$('#yourgrid').jqGrid({ 
    ..., 
    async: false, 
    loadComplete/gridComplete: function() { setSearchSelect('CM'); } 
    }); 
+0

是的,我注意到在我举的例子中,编辑它以便 var textsLength = texts.length 如果没有中断,var结果返回[],否则返回 \t [ “MR”,“CW”,“TB”] – Heather

+0

查看我的更新回答 –

+0

感谢您的帮助 - 我终于搞定了!事实证明,我只好把一切都在loadComplete功能 异步:假, \t \t loadComplete:函数(){ \t \t \t setSearchSelect( 'CM'); (“#name:'searchoptions:{sopt:['cn'],dataInit:function(elem){$(elem).autocomplete({source:getUniqueNames('名称'),延迟:0,minLength:0});}}}); \t \t \t $(“#dealsgrid”)。jqGrid('filterToolbar',{stringResult:true,searchOnEnter:true,defaultSearch:“cn”}); \t \t}, – Heather

相关问题