/** * Grid Util */ /** * 提供Grid中文設定參數,於頁面載入時設定。 * 須確保repository的檔案已經擁有中文對應檔。 * 原先的struts2-jquery-grid-plugin-2.4.1.jar * 當中並無中文設定檔,已經提供中文檔給peter重新製作jar檔。 * * 若要更新的話,請到下面路徑把該黨刪除,並重新執行PACI, * 該jar檔會重新下載。 * * ....路徑為.m2\repository\com\jgeppert\struts2\jquery\struts2-jquery-grid-plugin */ //發現問題=>路徑會因專案無法對應~先註解處理 /* $(document).ready(function(){ jQuery.scriptPath = "<%=request.getContextPath()%>/struts/"; jQuery.struts2_jquery.local = "zh-TW"; jQuery.struts2_jquery.gridLocal = "zh-TW"; jQuery.ajaxSettings.traditional = true; jQuery.ajaxSetup({ cache: false }); }); */ /** * * 使用範例: * 一般使用情境=> * $("#btnQuerySerNo").click(function(){ $("#button").val("btnQuerySerNo"); queryGrid("RP10!querySerNo", "#gridtableA"); }); * 指定頁面或狀態列使用情境=> //btnRefresh $("#btnRefresh").click(function(){ $("#button").val("btnQuerySerNo"); //call updaet... add... queryGrid("RP10!querySerNo", "#gridtableA", {page:$("input[class=ui-pg-input]").val(), msgId:".errText"}); }); * queryGrid說明: * @param: urlString => 指定此Grid的url屬性,會根據此屬性進行查詢。 * (Action 方法 ex: RP10!querySerNo) * gridTableId => 指定要呈現的GridTable String * (Selector ex: "#gridtableA") * param(option) => 提供兩個屬性: * page : 查詢後以該頁呈現(指定頁面更新,預設第一頁。) * rows : 指定查詢時要使用的查詢筆數。 * msgId : 可指定狀態列顯示(可指定狀態列,預設以'.msgText'顯示) * ({msgId : '.msgText', * page:$("input[class='ui-pg-input']" ).val(), * rows:$("select[class='ui-pg-selbox']" ).val(), * lastUrl:"RP01!queryGrid", * showMsg:false(預設會顯示~可關閉), * showGrid:false(預設會顯示~可關閉) * }) */ function queryGrid(urlString, gridTableId, param){ var jsonData; var showMsg = true; var showGrid = true; var msgId = '#statusMsg'; //下方狀態列 var msgWinId = '#window'; //彈跳視窗 var formData = $("form" ).serializeArray(); var lastUrl = urlString; var gridParam = jQuery.param(formData); var index; if (typeof param !='undefined') { //msgId defaultValue = "#statusMsg" (can Change) if (param['msgId'] != null && param['msgId'].lenght>0) { msgId = param['msgId']; } //lastUrl defaultValue = urlString; (can Change) if (param['lastUrl'] != null && param['lastUrl'].lenght>0) { lastUrl = param['lastUrl']; } //showMsg defaultValue = true (can Change) if (param['showMsg'] != null) { showMsg = param['showMsg']; } //showGrid defaultValue = true (can Change) if (param['showGrid'] != null) { showGrid = param['showGrid']; } //page added for formData if (param['page'] != null && param['page']>0) { // Find and replace `msgId` if there for (index = 0; index < formData.length; ++index) { if (formData[index].name == "page") { formData[index].value = param['page']; break; } } // Add it if it wasn't there if (index >= formData.length) { formData.push({ name: "page", value: param['page'] }); } } //rows added for formData if (param['rows'] != null && param['rows']>0) { // Find and replace `rows` if there for (index = 0; index < formData.length; ++index) { if (formData[index].name == "rows") { formData[index].value = param['rows']; break; } } // Add it if it wasn't there if (index >= formData.length) { formData.push({ name: "rows", value: param['rows'] }); } } } formData = jQuery.param(formData); $.ajax({ url: urlString, //"RP10!querySerNo", type: "POST", data: formData, async: false, //dataType: "json", success: function(json, status) { if (typeof json == 'string') { var errMsg = $(json).find("#jsonMsg").html(); $(msgWinId).html(errMsg); $(msgWinId).attr("style","color:red"); var errString = ""; listMsg = $(json).find("#jsonMsg").children("li"); for(var i = 0; i")); }else if(typeof json.message != 'undefined'){ $(msgId).val(json.message); $(msgWinId).html(json.message.replace("]", "]
")); } //處理status or success(廢棄) if(typeof json.status != 'undefined'){ if(json.status.toUpperCase().indexOf('OK')>=0){ $(msgId).attr("style","color:blue");//has effect $(msgWinId).attr("style","color:black"); }else{ $(msgId).attr("style","color:red"); $(msgWinId).attr("style","color:red"); } }else if(typeof json.success != 'undefined'){ if(json.success.toUpperCase().indexOf('OK')>=0){ $(msgId).attr("style","color:blue");//has effect $(msgWinId).attr("style","color:black"); }else{ $(msgId).attr("style","color:red"); $(msgWinId).attr("style","color:red"); } } } jsonData=json;//GridBean only } }, error: function(xhrInstance, status, xhrException) { message='發生伺服器例外錯誤'; $(msgId).val(message); $(msgWinId).html(message+"
"); $(msgId).attr("style","color:red"); $(msgWinId).attr("style","color:red"); } }); $.ajax({async: true}); return jsonData; }