123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- /*
- * 返回json格式中 最好默认带有ID列
- 默认显示 20列
- * 列表id = 'gridTable'
- 列表url = 'Handler.ashx?action=page'
- 列表datatype = 'json'
- 列表colNames = ['ID', '名称', '性别', '手机', '邮箱']
- 列表colModel = 。。。
- 列表标题 caption = '用户列表'
- 列表修改URL editurl = 'Handler.ashx?action=oper'
- 列表默认排序 sortname = 'ID';
- 页码ID gridPagerID = 'gridPager'
- */
- //最后选中的行
- var lastsel;
- function myJqGrid(id, url, datatype, colNames, colModel, caption, sortname,
- gridPagerID, sortorder, height, width, multiselect, rownumbers) {
- var myGrid = $('#' + id);
- myGrid.jqGrid({
- url : url,
- datatype : datatype,
- height : height,
- width : width,
- rowNum : 20,
- rowList : [ 10, 20, 50 ],
- colNames : colNames,
- colModel : colModel,
- loadtext : "读取数据中。。。",
- jsonReader : {
- repeatitems : false,
- root : function(obj) {
- return obj.rows;
- },
- page : function(obj) {
- return obj.pageindex;
- },
- total : function(obj) {
- return obj.pagecount;
- },
- records : function(obj) {
- return obj.total;
- }
- },
- prmNames : {
- page : 'page',
- rows : 'pageSize',
- sort : 'sortorder',
- order : 'sortname'
- },
- rownumbers : rownumbers,
- multiselect : multiselect,
- loadonce : false,
- sortname : sortname,
- sortorder : sortorder,
- pager : '#' + gridPagerID,
- viewrecords : true,
- caption : caption,
- // toolbar: [true, 'top'],
- //altRows : true,
- //editurl:"http://localhost:8080/healthsystem/hsindex.action",
- cellEdit : true,
- cellsubmit : 'clientArray',
-
- // 最后选中的行
- onSelectRow : function(id) {
- if (id && id !== lastsel) {
- myGrid.jqGrid('restoreRow', lastsel);
- myGrid.jqGrid('editRow', id, true);
- lastsel = id;
- //lastsel = myGrid.jqGrid('getRowData', id)[sortname];
- }
- },afterSaveCell : function(rowid, cellname, value, iRow, iCol) {
- //function saveData(){
- //var arr = $("#gridTable").getChangedCells('all'); // Return Rows
- var rowDatas = $("#gridTable").jqGrid('getRowData', rowid);
- var obj=new Object();
- obj.id=rowDatas.id;
- obj.hcode=rowDatas.hcode;
- obj.name=rowDatas.name;
- obj.gstatus=rowDatas.gstatus;
- obj.wpId=rowDatas.wpId;
-
- $.ajax({
- type:'post',
- dataType : "json",
- url:'../healthsystem/updateHealthSystem.action',
- data:{"obj":JSON.stringify(obj)},
- success:function(data){
- //alert(data);
- }
- });
- //}
- },loadComplete: function () {
- //debugger;
- //在表格加载完成后执行
- var ids = myGrid.jqGrid("getDataIDs");//获取所有行的id
- var rowDatas = myGrid.jqGrid("getRowData");//获取所有行的数据
- for(var ii=0;ii < rowDatas.length;ii++){
- var rowData = rowDatas[ii];
- if(rowData.status == 1){//如果某一行中的“status”为0,那就把这一整行的背景颜色设为红色
- myGrid.find("#"+ids[ii]+ " td").css("background-color","red");
- }
- }
- }
- });
- }
|