《JQGrid搜索等功能的配置》由会员分享,可在线阅读,更多相关《JQGrid搜索等功能的配置(29页珍藏版)》请在金锄头文库上搜索。
1、ConfigurationThecolumnsinthegridcanbeusedasthebasisforasearchformtoappearabove,below,orinplaceof,thegrid.Searchingisawayofqueryingdatafromtheserverusingspecifiedcriteria.Currentlywedonothavemoduleforsearchingonlocaldatai.ewhenadatatypeoptionsissettolocal.Allthesearchingisdoneserverside.Therearefoura
2、pproaches:atoolbarsearchingacustomsearchingasinglefieldsearchingamorecomplexapproachinvolvingmanyfieldsandconditions-advancedsearchingTheseapproachesusecommonoptionsfromjqGridandsocanbecalledonlyonanalready-constructedgrid.Everysearchmethodrequirethatsomeadditionalmoduleshouldbeincludedintothepackag
3、e.AlsorefertDownloadorineveryspecificmoduleonwhatshouldbeincludedAllsearchmodules(exceptcustomsearchingandtoolbarsearching)usesthefollowingdefinitionfromlanguagefile:II$.jgrid=1IIsearch:caption:Search.,Find:Find,Reset:Reset,odata:equal,notequal,less,lessorequal,greater,greaterorequal,beginswith,does
4、notbeginwith,isin,isnotin,endswith,doesnotendwith,contains,doesnotcontain,groupOps:op:AND,text:all,op:OR,text:any,matchText:match,rulesText:rules,colModelOptionsAsof3.5releasejqGridusesacommonsearchoptionsthatcanbeusedoneverysearchmethod.BelowisalistoftheseoptionsthatshouldbesetincolModel.Notethatso
5、meoptionsarenotapplicableforparticularmethod.OptionTypeDesscriptionDefaultsearchbooleanDeterminesifthefieldcanbesearched.truestypestringDeterminesthesearchtypeofthefield.Canbetext-alsoainputelementwithtypetextiscreatedandselect-aselectelementiscreatedtextsearchoptionsobjectObjectwhichcontaindefiniti
6、on,eventsandotherpropertiesforthesearchedfield.SeebelowThesearchoptionsobjecthavethefollowingproperties:Thesearchoptionsarenotapplicabletocustomsearchmethod.Thismethodusesseparateoptions.PropertyTypeDescriptiondataUrlstringThisoptionisvalidonlyfortheelementsoftypeselect-i.estype:select.Theoptionrepr
7、esenttheurlfromwhereweloadtheselectelement.Whenthisoptionissettheelementwillbefilledwithvaluesfromtheajaxrequest.Thedatashouldbeavalidhtmlselectelementwiththedesiredoptions.ByexampletherequestshouldcontainOneTwo.Thisiscalledonlyonce.buildSelectfunctionThisoptionhavesenseonlyifthedataUrlparameterisse
8、t.Incasewheretheserverresponsecannotbuildtheselectelementyoucanuseyouronfunctiontobuildtheselect.Thefunctionshouldreturnastringcontainingtheselectandoptionsvalue(s)asdescribedindataUrloption.ParameterpassedtothisfunctionistheserverresponsedatalnitfunctionIfsetthisfunctioniscalledonlyoncewhentheeleme
9、ntiscreated.Tothisfunctionwepasstheelementobject.dataInit:function(elem)dosomethingAlsousethisfunctiontoattachdatepicker,timepickerandetc.Example:dataInit:function(elem)$(elem).datepicker();dataEventsarrayListofeventstoapplytothedataelement;uses$(#id).bind(type,data,fn)tobindeventstodataelement.Shou
10、ldbedescribedlikethis:dataEvents:type:click,data:i:7,fn:function(e)console.log(e.data.i);,type:keypress,fn:function(e)console.log(keypress);attrobjectattrisobjectwherewecansetvalidattributestothecreatedelement.Byexample:attr:title:SometitleWillsetatitleofthesearchedelementsearchhiddenbooleanBydefaul
11、thiddenelemntsinthegridarenotsearchable.InordertoenablesearchingwhenthefieldishiddensetthisoptiontotruesoptarrayThisoptionisusedonlyinadvancedsinglefieldsearchinganddeterminestheoperationthatisappliedtotheelement.Ifnotsetalltheavailableoptionswillbeused.Allavailableoptionare:eq,ne,lt,le,gt,ge,bw,bn,
12、in,ni,ew,en,cn,ncThecorrespondingtextsareinlanguagefileandmeanthefollowing:equal,notequal,less,lessorequal,greater,greaterorequal,beginswith,doesnotbeginwith,isin,isnotintendswith,doesnotendwith,contains,doesnotcontainNotethattheelementsinsoptarraycanbemixedinanyorder.defaultValuestringIfnotemptyset
13、adefaultvalueinthesearchinputelement.valuemixedTheoptionisusedonlyforstypeselectanddefinestheselectoptionsinthesearchdialogs.WhensetforstypeselectanddataUrloptionisnotset,thevaluecanbeastringorobject.Iftheoptionisastringitmustcontainasetofvalue:labelpairswiththevalueseparatedfromthelabelwithacolon(:
14、)andendedwith(;).Thestringshouldnotendedwitha(;)-editoptions:value:1:One;2:Two.Ifsetasobjectitshouldbedefinedaspairname:value-editoptions:value:1:One;2:TwoNote:whenthedataUrlinsearchoptionsobjectisnotusedforthesearchtypeselect,thedefinitionsfortheselectaretakenfirstfromsearchoptionsvaluepropertyandifthisisnotdefinedaeditoptionsvaluepropertyisused-i.eeditoptions:value:“1:one;2:two”,.Seebelowhowtousetheseoptionsindifferentsearchmethods.colModelconventions:script:jQuery(#grid_id).jqGrid(colModel:name:price,index:price,width:6