1, add column in Jqgrid table, content is icon, define icon Click event, can manipulate data of this row, as
2. Front Code
<div id="grid_list"> <table id="gridtable" class="DataTable"></table> <div id=" Gridpager"></div></div>
3. JS Code
<script type="Text/javascript">$ (document). Ready (function () {Getgrid (); //bind keyboard Press event$ (document). KeyPress (function (e) {//Enter Event if(E.which = = -) { $("#keywords"). focus (); $("#keywords").Select(); $("#btnSearch"). Click (); } }); }); //Load Tablefunction Getgrid () {varSelectrowindx; $("#gridTable"). Jqgrid ({URL:"@Url. Content ("~/vehicle/vehicle/gridpagelistjson")", datatype:"JSON", Mtype:'POST', Height: $ (window). Height ()- the, Autowidth:true, Colmodel: [{label:'Coding', Name:'Clid', index:'Clid', Width: the, align:' Left', Hidden:false, Key:true}, {label:'Body Code', Name:'Vehicle_code', index:'Vehicle_code', Width: -, align:' Left', Hidden:false}, {label:'License plate number', Name:'CPH', index:'CPH', Width: -, align:' Left'}, {label:'enabled', Name:'Flag', index:'Flag', Width: $, align:'Center', Formatter:function (Cellvalue, Options, Rowobject) {if(Cellvalue = ='0')return ""+ Options.rowid +"\ ", 0) ' src= '. /.. /content/images/icon16/accept.png '/>"; if(Cellvalue = ='1')return ""+ Options.rowid +"\ ", 0) ' src= '. /.. /content/images/icon16/cross_shield.png '/>"; },}, {label:'Details', Name:"', index:'operate', Width: -, align:'Center', Formatter:function (Cellvalue, Options, Rowobject) {varDetail=""+ Rowobject.clid +"\ ") ' title= ' details ' src= '. /.. /content/images/icon16/application_view_detail.png ' style= ' padding:0px 10px ' >"; returndetail; },},], Viewrecords:true, RowNum: -, rowlist: [ -, -, -, -, +], Pager:"#gridPager", Sortname:'CLID', SortOrder:'desc', Rownumbers:true, ShrinkToFit:true, GridView:true, //Multiselect:true,onselectrow:function () {selectrowindx= Getjqgridrowindx ("#"+ This. Clid); }, Gridcomplete:function () {//loadviewlist (); //$ ("#" + this.id). Jqgrid (' setselection ', selectrowindx); } }); //self-response height$ (window). Resize (function () {$ ("#gridTable"). Setgridheight ($ (window). Height ()-178); }); } function Imgclick (rowid,type) {if(rowid=="") return; Ajaxjson ("//vehicle/vehicle/changestate", {Id:rowid,type:type}, function (Data) {if(Data.success = =true) { $("#gridTable"). Setcell (rowID,'Flag', Data.entity.FLAG); Tipdialog (Data.message,2,'Success'); } Else{tipdialog (data.message,2,'Warning'); } }); } //Detailfunction Btn_detail (ID) {varKeyValue = Getjqgridrowvalue ("#gridTable","Clid"); if(id!=NULL) {KeyValue=ID; } if(IsChecked (KeyValue)) {varURL ="/vehicle/vehicle/detail? Keyvalue="+KeyValue; Dialog (URL,"Detail","Vehicle Details", -, -, Function (iframe) {Top.frames[iframe]. Acceptclick (); }); } }</script>
4. Backstage Code
//user audits and enablement PublicActionResult Changestate (stringIdinttype) { if(string. IsNullOrEmpty (ID)) {returnContent (Newjsonmessage {Success =false, Code ="-1", Message ="vehicle ID is empty." }. ToString ()); } Try{sys_ambul_info entity=BASE_AMBLL. Repository (). Findentity (ID); //enabled, not enabled if(Type = =0) {entity. FLAG= entity. FLAG = =0?1:0; } Else return NULL; intIsOk =BASE_AMBLL. Repository (). Update (entity); returnContent (Newjsonmessage {Success =true, entity = entity, Message ="Operation succeeded" }. ToString ()); } Catch(Exception ex) {returnContent (Newjsonmessage {Success =false, Code ="-1", Message ="operation failed:"+Ex. Message}. ToString ()); } }
5. Note:
5.1 Because the database primary key field is not an ID, it is clid. So the front desk Colmodel to set the column Clid key:true
{label: ' encoded ', Name: ' Clid ', index: ' Clid ', width:80, align: ' Left ', hidden:false},
If not set, so that the front-end to obtain the ROWID is always obtained is the serial number, the effect is as follows:
{label: ' encoded ', Name: ' Clid ', index: ' Clid ', width:80, align: ' left ', Hidden:false, key:true},
5.2 Because the clid is preceded by a number of 0, the value is converted to a string, otherwise the value will not be accurate
Add double quotes around Options.rowid
Return "\""+ options.rowid +"\ ", 0) ' src= '. /.. /content/images/icon16/accept.png '/> ';
Jqgrid plus button Column