MvcJqGrid工具栏搜索SetSearchOption不起作用

时间:2014-10-09 14:11:13

标签: jqgrid jqgrid-asp.net mvcjqgrid

我的MvcJqGrid中有一个Gender列,我在设置过滤器时遇到了困难。我目前将其设置为:

.AddColumn(new Column("Gender").SetLabel(" ")
    .SetSearchType(Searchtype.Select)
    .SetSearchTerms((Dictionary<string, string>)ViewData["GenderArray"])
    .SetSearchOption(SearchOptions.BeginsWith)
)

这应该是我想要的男性/女性是您可以选择的唯一选项,以及显示的唯一结果。但它总是像我使用'包含'一样运作,当你选择男性时,女性结果总会显示出来。我认为它根本不接受SearchOption,因为我设置它似乎并不重要。我甚至试图通过区分大小写来过滤它,但它似乎是不区分大小写的,尽管我不认为它应该是。

我的全网格:

@(Html.Grid("SearchGrid")
.SetLoadUi(LoadUi.Block)
.SetLoadText("Loading Results...")
.AddColumn(new Column("ID")
    .SetLabel("&nbsp;")
    .SetSearch(false)
    .SetSortable(false)
    .SetEditable(false)
    .SetCustomFormatter("CreateSelectButton")
    .SetWidth(150)
    .SetAlign(Align.Center))
.AddColumn(new Column("FirstName").SetLabel("&nbsp;"))
.AddColumn(new Column("LastName").SetLabel("&nbsp;"))
.AddColumn(new Column("DateOfBirth").SetLabel("&nbsp;")
    .SetFormatter(Formatters.Date)
    .SetSearchType(Searchtype.Datepicker))
.AddColumn(new Column("State").SetLabel("&nbsp;")
    .SetSearchType(Searchtype.Select)
    .SetSearchTerms((Dictionary<string, string>)ViewData["StateArray"])
    .SetSearchOption(SearchOptions.BeginsWith)
)
.AddColumn(new Column("Country").SetLabel("&nbsp;"))
.AddColumn(new Column("Gender").SetLabel("&nbsp;")
    .SetSearchType(Searchtype.Select)
    .SetSearchTerms((Dictionary<string, string>)ViewData["GenderArray"])
    .SetSearchOption(SearchOptions.BeginsWith)
)
.SetSortName("LastName")
.SetUrl(String.Format("myurl/SearchGridDataAsync?FirstName={0}&LastName={1}&DOB={2}&State={3}&Country={4}&Gender={5}&Prefix={6}&DavContactId={7}",
    Model.FirstName,
    Model.LastName,
    Model.DateOfBirth,
    Model.State,
    Model.Country,
    Model.Gender,
    Model.Prefix,
    Model.ID))
.SetRowNum(20)
.SetPager("Pager")
.SetEmptyRecords("<div class=\"bigger-110 red center\"><i class=\"icon-warning-sign icon-x2\"></i> 0 results found!</div>")
.SetRowList(new[] { 5, 10, 20 })
.SetViewRecords(true)
.SetSearchOnEnter(false)
.SetSearchToolbar(true)
.SetSearchClearButton(true)
.SetShowAllSortIcons(true)
.SetAutoWidth(true)
.SetShrinkToFit(true)

设置:

{
    gridsel: '#SearchGrid',
        labels: [
            { label: 'FirstName', text: 'First Name' },
            { label: 'LastName', text: 'Last Name' },
            { label: 'DateOfBirth', text: 'Date Of Birth' },
            { label: 'State', text: 'State' },
            { label: 'Country', text: 'Country' },
            { label: 'Gender', text: 'Gender' }]
}

GenderArray包含:

Dictionary<string,string> collection = new Dictionary<string,string>();
            collection.Add("Male","Male");
            collection.Add("Female","Female");

编辑:我刚刚没有将MvcJqGrid nuget包更新为version =“1.0.15”,并手动将我的jquery.jqGrid.min.js文件更新为4.5.4,这是我在github页面中看到的。生成的js很难获得,因为我在搜索后使用AJAX将其加载到局部视图中,但在移动了一些东西之后,这就是我得到的:

<div class="col-xs-12 col-sm-12 col-md-9 col-lg-9" id="jqGridResults">
    <script type="text/javascript">
        jQuery(document).ready(function () {
            jQuery('#SearchGrid').jqGrid({
                autowidth:true,
                datatype:'json',
                emptyrecords:'<div class="bigger-110 red center"><i class="icon-warning-sign icon-x2"></i> 0 results found!</div>',
                height:'100%',
                loadtext:'Loading Claimant Results...',
                loadui:'block',
                pager:'#Pager',
                rowList:[5,10,20],
                rowNum:20,
                sortname:'LastName',
                viewsortcols:[true,'vertical',true],
                shrinkToFit:true,
                url:'/Claimant/FindClaimant/SearchGridDataAsync?FirstName=&LastName=&DOB=&State=&Country=&Gender=&Prefix=&DavContactId=',
                viewrecords:true,
                gridComplete: function() {claimant.gridresize( { gridid : '#SearchGrid'} )},
                colModel: [
                {
                align:'center',
                name:'DAVContactID',
                formatter:claimant.CreateSelectButton,
                label:'&nbsp;',
                search:false,
                sortable:false,
                width:150,
                editable:false,
                index:'DAVContactID'
                },{
                name:'FirstName',
                label:'&nbsp;',
                index:'FirstName'
                },{
                name:'LastName',
                label:'&nbsp;',
                index:'LastName'
                },{
                name:'DateOfBirth',
                formatter:'date',
                label:'&nbsp;',
                searchoptions: { sopt:['bw'], dataInit:function(el){$(el).datepicker({changeYear:true, onSelect: function() {var sgrid = $('#SearchGrid')[0]; sgrid.triggerToolbar();},dateFormat:'dd-mm-yy'});} },
                index:'DateOfBirth'
                },{
                name:'State',
                label:'&nbsp;',
                stype:'select',
                searchoptions: { sopt:['bw'], value:":;AL:Alabama;AK:Alaska;AZ:Arizona;AR:Arkansas;CA:California;CO:Colorado;CT:Connecticut;DE:Delaware;FL:Florida;GA:Georgia;HI:Hawaii;ID:Idaho;IL:Illinois;IN:Indiana;IA:Iowa;KS:Kansas;KY:Kentucky;LA:Louisiana;ME:Maine;MD:Maryland;MA:Massachusetts;MI:Michigan;MN:Minnesota;MS:Mississippi;MO:Missouri;MT:Montana;NE:Nebraska;NV:Nevada;NH:New Hampshire;NJ:New Jersey;NM:New Mexico;NY:New York;NC:North Carolina;ND:North Dakota;OH:Ohio;OK:Oklahoma;OR:Oregon;PA:Pennsylvania;RI:Rhode Island;SC:South Carolina;SD:South Dakota;TN:Tennessee;TX:Texas;UT:Utah;VT:Vermont;VA:Virginia;WA:Washington;WV:West Virginia;WI:Wisconsin;WY:Wyoming" },
                index:'State'
                },{
                name:'Country',
                label:'&nbsp;',
                index:'Country'
                },{
                name:'Gender',
                label:'&nbsp;',
                stype:'select',
                searchoptions: { sopt:['bw'], value:":;Male:Male;Female:Female" },
                index:'Gender'
                }]});
            jQuery('#SearchGrid').jqGrid('navGrid',"#Pager",{edit:false,add:false,del:false,search:false,refresh:false}); 
            jQuery('#SearchGrid').jqGrid('navButtonAdd',"#Pager",{caption:"Clear",title:"Clear Search",buttonicon :'ui-icon-refresh', onClickButton:function(){jQuery('#SearchGrid')[0].clearToolbar(); }}); 
            jQuery('#SearchGrid').jqGrid('filterToolbar', {stringResult:true, searchOnEnter:false});
    });
</script>

0 个答案:

没有答案