var contextPath = document.location.pathname; contextPath = contextPath.substr(0,contextPath.substr(1).indexOf('/')+1)+'/a';/** * jqgrid通用列表展示 后期还需要封装 * @param tableList * @param columns * @param config */function searchDataList(tableList , columns, config){ var formJson = ''; if(document.getElementById('searchForm')) formJson = changeAjaxFormData($('#searchForm')); tableList.jqGrid({ url: config.url, datatype: 'json', toolbar: config.toolbar, styleUI: 'Bootstrap',// 设置jqgrid的全局样式为bootstrap样式 colModel:columns, postData:formJson, // 发送数据 viewrecords: true,
autowidth: true, height: '100%', altRows:true, rowNum: 30, rowList : [30,60,100], rownumbers: true, rownumWidth: 25, autowidth:true, multiselect: config.multiselect, pager: '#jqGridPager', jsonReader : { root: 'list', page: 'pageNo', total: 'last', records: 'count' },
prmNames : { page:'pageNo', rows:'pageSize', order: 'order' }, gridComplete:function(){ tableList.closest('.ui-jqgrid-bdiv').css({ 'overflow-x' : 'hidden' }); }});}
/** * 列表查询 * @param tableList * @param url */function doSearch(tableList, url){$('#searchBtn').click(function(){reloadGrid(tableList, url);});}/** * 重新加载列表 * @param tableList * @param url */function reloadGrid(tableList, url){formJson = changeAjaxFormData($('#searchForm'));tableList.jqGrid('setGridParam',{postData:formJson}); tableList.jqGrid('setGridParam',{page:1}); tableList.jqGrid('setGridParam',{url: url}).trigger('reloadGrid');}/** * 查询重置列表 */ function resetForm(){$('#resetBtn').click(function(){$('#searchForm')[0].reset();});}
/** * 列表增加toolbar * @param toolbarDiv * @param toolbarGrid */function appendToolbar(toolbarDiv, toolbarGrid){toolbarDiv.appendTo('#'+toolbarGrid);}/** * 获得checkbox选中的值 * @param tableList * @returns */function gridCheckSelected(tableList){return tableList.jqGrid('getGridParam', 'selarrrow');}
/** * 通用删除 * @param tableList * @param delUrl * @param gridUrl */function commonDelete(tableList, delUrl, gridUrl){$('#del_btn').click(function(){var checkValue = gridCheckSelected(tableList);if(checkValue == undefined || checkValue == '') {$.jBox.tip('请选择需要删除的数据!','warn');return;}$.jBox.confirm('确认删除这些数据吗?','系统提示',function(v,h,f){if(v=='ok'){ajaxTemplate(delUrl, 'json', true, {'ids': ''+checkValue+''}, '', tableList , gridUrl );}},{buttonsFocus:1});$('.jbox-body .jbox-icon').css('top','55px');});}function commonEdit(addUrl, preValid, preAdd, afterAdd){var valid = {'flag':true, 'message':''};if(preValid != undefined && preValid !='' && preValid !=null){valid = preValid();}if(valid.flag){if(preAdd != undefined && preAdd !='' && preAdd !=null){preAdd();}if(!$('#actionForm').validationEngine('validate')){return ;}
var formJson = changeAjaxFormData($('#actionForm'));ajaxTemplate(addUrl,'json', true, formJson, function(data){if(data.code == '1'){$.jBox.tip(data.message,'info');if(afterAdd != undefined && afterAdd !='' && afterAdd !=null){afterAdd(data);}}else{$.jBox.tip(data.message,'error');}});}else{$.jBox.tip(valid.message, 'error');valid.item.focus();}}