初始化加载数据
$("#jqGrid").jqGrid({ url: 'CCProjectileInfo.aspx?Action=GetInBillList', //url: 'http://trirand.com/blog/phpjqgrid/examples/jsonp/getjsonp.php?callback=?&qwery=longorders', mtype: "GET", styleUI: 'Bootstrap', datatype: "json", postData: { UserID: userId }, colModel: [ //{ label: '交流类型', name: 'ID', key: true, 200 }, { label: '交流类型', name: '', 200, formatter: function (value, grid, rows, state) { return "Inbound交流记录" } }, { label: '处理时间', name: 'CreateDate', 170, formatter: function (value) { return value.replace("T", " ") } }, { label: '处理账号', name: 'CreateBy', 100 }, { label: '反馈内容', name: 'FromContent', 300 }, { label: '回馈内容', name: 'ToContent', 300 }, { label: '操作', name: '', 100, formatter: function (value, grid, rows, state) { return "<a href="javascript:void(0)" style="color:#f60" onclick="ShowBoundInfo(" + rows.ID + ",1)">查看</a>" } } ], viewrecords: true, height: 250, rowNum: 20, rowList: [10, 20, 50, 100], //每页记录数可选列表 pager: "#jqGridPager" });
添加数据,后刷新jqGrid列表
$("#btnSaveOutBill").bind("click", function () { if ($("#dfjg").val() == "" || $("#khdy2").val() == "" || $("#wyzt").val() == "") { layer.msg("所有标红的为必填项!", { icon: 2 }); return; } if (userId < 1) { layer.msg("请先保存用户基本信息!", { icon: 2 }); return; } $.ajax({ url: 'CCProjectileInfo.aspx?Action=AddOutBill&UserID=' + userId, data: { handleAccount:$(".handAccount").eq(2).val(), hfzt: $("#hfzt").val(), dfjg: $("#dfjg").val(), dfsm: $("#dfsm").val(), khdy: $("#khdy2").val(), wyzt: $("#wyzt").val(), cpsl: $("#cpsl2").val(), sfth: $("#rdb_sfths2").is(":checked"), yjlp: $("#rdb_yjlps2").is(":checked"), jtdf: $("#rdb_jtdfs2").is(":checked"), jsdx: $("#rdb_jsdxs2").is(":checked"), ygyl: $("#ygyl").val(), zpyy: $("#zpyy2").val(), zppp: $("#zppp2").val(), zpsj: $("#zpsj2").val(), fknr: $("#fknr2").val(), hknr: $("#hknr2").val() }, success: function (r) { if (r == true) { layer.msg("添加成功!", { icon: 1 }); var outdata = { UserID: userId }; $("#jqGrid2").jqGrid('setGridParam', { datatype: 'json', postData: outdata, //发送数据 page: 1 }).trigger("reloadGrid"); //重新载入 //$("#jqGrid2").trigger("reloadGrid"); //刷新数据列表 } else layer.msg("添加失败!", { icon: 2 }); } }) })
按条件搜索后,刷新列表
$("#btn_jfSearch").bind("click", function () { var jfData = { jflx: $("#jf_jflx").val(), jfkssj: $("#jf_startTime").val(), jfjssj: $("#jf_endTime").val(), jfcp: $("#jf_procuct").val(), mdbh: $("#jf_clientCode").val(), mdmc: $("#jf_clientName").val(), jf_dg: $("#jf_dg").val(), jf_kf: $("#jf_kf").val() }; //alert(JSON.stringify(jfData)) // $('#jqGrid_jf').jqGrid('clearGridData'); //清空表格 数据 $("#jqGrid_jf").jqGrid('setGridParam', { datatype: 'json', postData: jfData, //发送数据 page: 1 }).trigger("reloadGrid"); //重新载入 })
后台分页获取列表数据
public string GetBillList(int type) { int UserID = Convert.ToInt32(Request.Params["UserID"]); int pageIndex = Convert.ToInt32(Request.Params["page"]); int pageSize = Convert.ToInt32(Request.Params["rows"]); int totalRecord = recordBll.GetRecordCount(" UserID=" + UserID + " and Type=" + type); int totalPage = (totalRecord / pageSize) + ((totalRecord % pageSize) > 0 ? 1 : 0); DataSet ds = recordBll.GetListByPage(" Type=" + type + " and UserID=" + UserID, "", (pageIndex - 1) * pageSize, pageIndex * pageSize); List<Maticsoft.Model.CRM.CRM_ACRecord> list = recordBll.DataTableToList(ds.Tables[0]); return JsonConvert.SerializeObject(new PageDataModel() { records = totalRecord, page = pageIndex, total = totalPage, rows = list }); }